Python / Django测试一次只运行一个测试

时间:2013-10-21 15:52:17

标签: python django unit-testing

我的观点有单位测试

class TestFromAllAdd(TestCase):
    fixtures = ['staging_accounts_user.json',
        'staging_main_category.json',
        'staging_main_dashboard.json',
        'staging_main_location.json',
        'staging_main_product.json',
        'staging_main_shoppinglist.json']

    def setUp(self):
        self.factory = RequestFactory()
        self.c = Client()
        self.c.login(username='admin', password='admin')

    def from_all_products_html404_test(self):
        request = self.factory.post('main/adding_from_all_products', {'product_id': ''})
        request.user = User.objects.get(username= 'admin')
        response = adding_from_all_products(request)
        self.assertEqual(response.status_code, 404)

但我还有一些测试类,我不能同时运行它们: python manage.py test main没有运行测试,但如果我运行; python manage.py test main.TestFromAllAdd.from_all_products_html404_test,进行一次测试;

2 个答案:

答案 0 :(得分:1)

Unittest方法需要以单词test开头(不以它结束)。您的方法应该被称为test_from_all_products_html404

答案 1 :(得分:1)

Pyrhon测试要求所有方法都以测试字开头,因此我的方法必须重命名为test_from_all_products_html404_test