source

py.test에 특정 디렉토리를 건너뛰도록 지시하는 방법은 무엇입니까?

itover 2023. 7. 16. 18:17
반응형

py.test에 특정 디렉토리를 건너뛰도록 지시하는 방법은 무엇입니까?

setup.cfg 내부의 옵션을 사용하여 py.test에 특정 디렉토리에서 테스트를 수집하지 않도록 하려고 했지만 무시하는 것 같습니다.

[tool:pytest]
norecursedirs=lib/third

실행할 때py.test어떻게 내부에서 테스트를 받는지 알 것 같습니다.lib/third!

py.test --ignore=somedir나를 위해 일했습니다.

파이테스트에서.ini:

[pytest]
addopts = --ignore=somedir --ignore=someotherdir

부모가 다른 디렉토리가 여러 개 있는 경우 다른 디렉토리를 지정할 수 있습니다.--ignore매개 변수:

py.test --ignore=somedir --ignore=otherdir --ignore=etcdir

  • 새 옵션: --vmx를 사용하면 지정된 경로를 수집할 수 없습니다.
    여러 번 지정할 수 있습니다.

저는 미스터리를 풀었습니다: 가능한 구성 파일 중 하나에서 파이테스트 섹션이 발견되면 (pytest.ini,tox.ini그리고.setup.cfg), pytest는 다른 것을 찾지 않으므로 단일 파일에서 py.test 옵션을 정의해야 합니다.

를 사용하는 것이 좋습니다.setup.cfg.

사용할 수 있습니다.

py.test -k 'not third'

모든 '세 번째' 디렉터리 내용을 제외합니다.

저의 경우, 문제는 누락된 와일드카드였습니다.다음은 저에게 적합합니다.

[tool:pytest]
norecursedirs = subpath/*

반면에 단지norecursedirs = subpath하지 않았다.

norecursedirs작동해야 합니다.파이 테스트가 있는지 확인합니다.ini 또는 다른 setup.cfg 파일.어떻게 호출하십니까?py.test?

setup.cfg를 사용하는 경우 다음을 사용해야 합니다.[tool:pytest]http://doc.pytest.org/en/latest/example/pythoncollection.html 에 따르면

파이테스트의 내용물이니
tox.ini 또는 setup.cfg 파일에도 정의할 수 있습니다. 단, 섹션은
setup.cfg 파일의 이름은 "tool:pytest"여야 합니다.

사용하기pytest.ini(사용하지 않는 한 권장)tox어떤 경우에tox.ini이해할 수 있음), 통화pytest와 함께pytest -c pytest.ini.

나의 샘플을 막기 위해서입니다.not_me_1.py그리고.not_me_2.py테스트를 받거나 보풀을 씌우는 것으로부터, 나의.pytest.ini는 다음과 같습니다.

[pytest]
addopts = --ignore-glob=not_me_*

[pycodestyle]
ignore = not_me_* ALL

언급URL : https://stackoverflow.com/questions/11117062/how-to-tell-py-test-to-skip-certain-directories

반응형