我有一个包含unittest-module的目录和一个用于编写调试信息的logs
-目录。因为我使用了-f
/--looponfail
选项,所以我需要忽略logs
-目录中的更改。
tests$ ls
logs __pycache__ pytest.ini test_basic.py
tests$ cat pytest.ini
[pytest]
norecursedirs = logs
python_files = test_*.py
tests$ py.test -h
(...)
[pytest] ini-options in the next pytest.ini|tox.ini|setup.cfg file:
markers (linelist) markers for test functions
norecursedirs (args) directory patterns to avoid for recursion
usefixtures (args) list of default fixtures to be used with this project
python_files (args) glob-style file patterns for Python test module discovery
python_classes (args) prefixes for Python test class discovery
python_functions (args) prefixes for Python test function and method discovery
addopts (args) extra command line options
minversion (string) minimally required pytest version
rsyncdirs (pathlist) list of (relative) paths to be rsynced for remote distributed testing.
rsyncignore (pathlist) list of (relative) glob-style paths to be ignored for rsyncing.
looponfailroots (pathlist) directories to check for changes
最终在循环中调用失败的测试,因为监视logs/test_basic.log
中的更改,我想知道为什么会这样。
looponfailroots
现在解决了这个问题。把它放到你的setup.cfg
:
[tool:pytest]
looponfailroots=mylib
pytest-xdist没有影响在--looponfail
上忽略哪些文件的选项。norecursedirs
只影响作为测试收集的文件。
正如@hpk42指出的那样,norecursedirs
只影响测试收集,而不影响文件系统监控。
因此,一种可能的处理方法是将日志移出test目录。