我的观点有单位测试
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
,进行一次测试;
答案 0 :(得分:1)
Unittest方法需要以单词test
开头(不以它结束)。您的方法应该被称为test_from_all_products_html404
。
答案 1 :(得分:1)
Pyrhon测试要求所有方法都以测试字开头,因此我的方法必须重命名为test_from_all_products_html404_test