4

我编写了一个用于处理文件权限的小实用程序包。结构遵循Python 包标准

.
|-- __init__.py                     # All the code is here, for now
`-- tests
    |-- __init__.py
    |-- permission_mode.feature     # Feature files for behave
    |-- steps                       
    |   |-- __init__.py
    |   `-- steps.py                # Step files for behave
    `-- test_modtools.py            # Nose tests

鼻子和行为都可以从命令行运行测试,没有问题:

鼻子:

$ nosetests
.
----------------------------------------------------------------------
Ran 1 test in 0.002s

OK

表现:

$ behave
Feature: Lots of cheese # permission_mode.feature:1

  Scenario: blah  # permission_mode.feature:2
    Given a       # steps/steps.py:1 0.000s
    Then b        # steps/steps.py:5 0.000s

1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
2 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.000s

我的setup.py文件包含以下测试规范:

test_suite='nose.collector',
tests_require=['nose']

因此python setup.py test以与 . 相同的输出运行鼻子测试nosetests

如何将行为配置为包的测试工具,以便python setup.py test运行行为?

4

2 回答 2

3

从行为中查看“setup.py”。它包含并置的“setuptools_behave.py”测试运行器的使用(并安装它)。

使用方法:

# -- file:setup.py
from setuptools_behave import behave_test
...

setup(
    ...
    tests_require=["behave>=1.2.4"],
    cmdclass = {
        "behave_test": behave_test,
    },
    ...    
)

要验证它,请执行“python setup.py --help-commands”。它应该包含一个命令“behave_test”。否则,运行“python setup.py behavior_test --help”。

于 2014-04-07T00:22:56.547 回答
1

看看这个提交提供简单的测试运行器来从 setup.py 运行行为测试

也许下一个版本?

于 2014-02-11T10:24:13.997 回答