【问题标题】:Why does the Django Behave test runner say "ignoring label with dot" when I run a single unit test?当我运行单个单元测试时,为什么 Django Behave 测试运行器会说“忽略带点的标签”?
【发布时间】:2016-12-05 19:27:09
【问题描述】:

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

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

我明白了

忽略带有点的标签:myapp.tests.tests_a

然后tests_a.py 运行。伟大的!只有我想运行的测试运行。但是测试运行者在谈论忽略什么?我还没有找到另一个运行我想要的测试但不发出警告的调用。这是怎么回事?

Django 1.10.2,django-behave 0.1.5。

【问题讨论】:

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


    【解决方案1】:

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

    python manage.py test app1 app2
    

    执行此操作时,它会加载属于每个应用的功能。您可以在django_behave/runner.py 中看到该代码。我在此处提供的链接指向撰写此答案时的最新已发布 版本。在该模块中,您会发现:

    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 的应用并失败。

    尚未发布的最新版本代码不再发布关于忽略标签的通知。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      • 2012-11-28
      • 2020-07-23
      相关资源
      最近更新 更多