当我运行单个单元测试时,为什么Django Behave测试运行程序会说“忽略带点的标签”?

2024-10-04 07:34:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我进行了验收测试和单元测试/django.测试单元测试。我有

TEST_RUNNER = 'django_behave.runner.DjangoBehaveTestSuiteRunner'

settings.py中。我有多个单元测试文件:

myapp/tests
  __init.py__ # empty
  tests_a.py
  tests_b.py

我想运行一个单元测试文件。(没有一个特写,我知道怎么做。)

python manage.py test myapp.tests.tests_a

我明白了

Ignoring label with dot in: myapp.tests.tests_a

然后tests_a.py运行。太好了!只有我想运行的测试运行了。但是试跑者在说什么呢?我还没有找到另一个调用来运行我想要的测试,但不会发出警告。这是怎么回事?你知道吗

Django 1.10.2,Django 0.1.5。你知道吗


Tags: 文件djangopytestsettingsinittests单元测试
1条回答
网友
1楼 · 发布于 2024-10-04 07:34:20

django-behave允许这样传递应用程序名称:

python manage.py test app1 app2

执行此操作时,它将加载属于每个应用程序的功能。您可以在^{}中看到该代码。我在这里给出的链接指向撰写此答案时发布的最新版本。在该模块中,您将发现:

def build_suite(self, test_labels, extra_tests=None, **kwargs):
    extra_tests = extra_tests or []
    #
    # Add BDD tests to the extra_tests
    #

    # always get all features for given apps (for convenience)
    for label in test_labels:
        if '.' in label:
            print("Ignoring label with dot in: %s" % label)
            continue
        app = get_app(label)

        # Check to see if a separate 'features' module exists,
        # parallel to the models module
        features_dir = get_features(app)
        if features_dir is not None:
            # build a test suite for this directory
            extra_tests.append(self.make_bdd_test_suite(features_dir))

    return super(DjangoBehaveTestSuiteRunner, self
                 ).build_suite(test_labels, extra_tests, **kwargs)

当代码遇到一个带有点的标签时,它会假定它不是一个应用程序名,并跳过它。所以你可以:

python manage.py test app1 app2 some.module.name

而且some.module.name不会导致django-behave尝试加载名为some.module.name的应用程序并失败。你知道吗

该代码的最新版本(尚未发布)不再发布关于忽略标签的通知。你知道吗

相关问题 更多 >