【问题标题】:Python/Django tests running only one test at a timePython/Django 测试一次只运行一个测试
【发布时间】:2013-10-30 05:15:49
【问题描述】:

我的视图有一个单元测试

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,运行一项测试;

【问题讨论】:

  • 里面有问题吗?最后一句话似乎回答了标题中的内容......
  • 问题是我想编写 python manage.py test main 并运行所有测试
  • 如果您想在名为“main”的 django 应用程序中运行所有测试,那么python manage.py test main 是正确的方法。你遇到了什么错误?

标签: python django unit-testing


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    Python测试要求所有方法都以test word开头,所以我的方法必须重命名为test_from_all_products_html404_test

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-10
      • 1970-01-01
      • 2017-10-19
      相关资源
      最近更新 更多