2016-04-22 53 views
0

运行模块级py.test灯具说我有这样的不上的每个子模块

$ tree 
. 
├── A 
│   ├── __init__.py 
│   ├── conftest.py 
│   ├── test_set_1.py 
│   └── test_set_2.py 
├── B 
│   ├── __init__.py 
│   ├── conftest.py 
│   ├── test_set_1.py 
│   └── test_set_2.py 
├── C 
│   ├── __init__.py 
│   ├── conftest.py 
│   ├── test_set_1.py 
│   └── test_set_2.py 
├── conftest.py 
├── pytest.ini 

我想定义一个pytest夹具,我可以指定一次特定运行的目录结构顶层模块(AB,或C),却一次也没有为每个子模块(test_set_1.pytest_set_2.py等)

我怎样才能做到这一点?我可以以某种方式在__init__.py文件中注入这些依赖关系吗?

回答

0

几个小时后,我想出了一个可行的答案:夹具的scope="session"参数适用于所有子模块。因此,如果A/conftest.py在其中具有会话级别的夹具,那么它仅对该子模块中的所有测试运行一次,但不运行用于其他子模块中的测试。