【问题标题】:How can I change the django-behave test runner's test file discovery pattern?如何更改 django-behave 测试运行器的测试文件发现模式?
【发布时间】:2016-12-14 21:19:31
【问题描述】:

我有一个带有行为特性和单元测试测试的 Django 项目。单元测试测试的组织方式如下:

theproject/
    theapp/
        tests/
            tests_one.py
            tests_other.py
            ...

必须在测试文件前加上“tests_”前缀,这很烦人。

如果我重命名所有没有“tests_”的测试文件并将我的测试运行器更改为

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

在 settings.py 中做

python manage.py test -p '*.py'

我所有的单元测试都运行,但不是我的行为特性。

当我有

TEST_RUNNER = 'django_behave.runner.DjangoBehaveTestSuiteRunner'

在 settings.py 中做

python manage.py test

我的功能运行但不是我的单元测试测试。

django-behave runner 没有 -p 标志或我可以看到的等效项。

如何让 django-behave 运行程序发现名称不以“tests_”开头的文件中的测试?

【问题讨论】:

  • 我没有使用行为,但也想更改搜索的文件。

标签: python django python-2.7 python-unittest python-behave


【解决方案1】:

我通过从 django-behave 切换到 behavior-django 解决了这个问题。

behave-django 不需要将 Django TEST_RUNNER 设置为它自己的测试运行器,因此 python manage.py test -p '*.py' 可以工作。

behave-django 不提供运行单元测试和验收测试的单个 Django 管理命令。我通过编写新的管理命令解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多