Can I make the pytest doctest module ignore a file?
我们使用pytest来测试我们的项目,并且默认情况下启用了
但是,有一个
我尝试将其放在
唯一有效的方法是将
有没有一种方法可以使doctest模块仅忽略某个文件?
您可以使用挂钩有条件地从测试发现中排除某些文件夹。
https://docs.pytest.org/en/latest/writing_plugins.html
1 2 3 4 5 | def pytest_ignore_collect(path, config): """ return True to prevent considering this path for collection. This hook is consulted for all files and directories prior to calling more specific hooks. """ |
正如MasterAndrey所提到的,
例:
1 2 3 4 5 6 7 8 9 | import sys def pytest_ignore_collect(path): if sys.version_info[0] > 2: if str(path).endswith("__py2.py"): return True else: if str(path).endswith("__py3.py"): return True |
从pytest v4.3.0开始,还有