py.test를 사용하면 다른 디렉토리에서 동일한 테스트를 수행하여 py.test가 실패하게됩니다. 왜 그런가요? 모든 테스트의 이름을 바꾸지 않고 어떻게 변경할 수 있습니까? 복제py.test - 다른 디렉토리의 테스트가 동일하게 호출 될 때 테스트 검색 실패
는 수행
; cd /var/tmp/my_test_module
; mkdir -p ook/test
; mkdir -p eek/test
; touch ook/test/test_proxy.py
; touch eek/test/test_proxy.py
; py.test
============================= test session starts ==============================
platform linux2 -- Python 2.7.3 -- pytest-2.2.4
collected 0 items/1 errors
==================================== ERRORS ====================================
___________________ ERROR collecting ook/test/test_proxy.py ____________________
import file mismatch:
imported module 'test_proxy' has this __file__ attribute:
/home/ygolanski/code/junk/python/mymodule/eek/test/test_proxy.py
which is not the same as the test file we want to collect:
/home/ygolanski/code/junk/python/mymodule/ook/test/test_proxy.py
HINT: remove __pycache__/.pyc files and/or use a unique basename for your test file modules
=========================== 1 error in 0.01 seconds ============================
나는 __init__.py를 요구하는 것이 합리적이라는 데 동의합니다. 테스트가 패키지에없는 경우, 본질적으로 최상위 모듈 (OP의 test_proxy)이며 하나만 있어야합니다. 테스트 모듈을 관련 패키지 (ook 및 eek)에 넣음으로써 테스트의 적절한 네임 스페이스를 제공합니다. 나는 현상 유지가 최고라고 말한다. 이 질문에 대한 오류 메시지 링크 또는 문제 해결을위한 추론과 기술을 설명하는 문서의 일부가 통증을 완화 할 수 있습니다. –
py.test docs는 테스트 디렉토리에'__init __. py'를 넣지 말 것을 권장합니다 : _ "__init __. py' 파일을 테스트 디렉토리에 넣지 마십시오. 이렇게하면 설치된 mypkg 버전에 대해 테스트를 쉽게 실행할 수 있습니다. 설치된 패키지에 테스트가 포함되어 있는지 여부와는 독립적으로 "_. [pytest.org - Good Integration Practices] (http://pytest.org/latest/goodpractises.html#choosing-a-test-layout-import-rules)에서 가져 왔습니다. – famousgarkin
업데이트 : 위의 @ famousgarkin의 의견과 answer (https://stackoverflow.com/a/21942491/260303)의 권장 사항은 더 이상 문서에 나타나지 않습니다. (최소한 "피하는"은 견적을 제기하지 않습니다. 위) : https://docs.pytest.org/en/latest/goodpractices.html#tests-as-part-of-application-code. 사실,이 링크의 예제는 테스트 디렉토리에'__init __. py'를 보여 주므로, 받아 들인 대답이 정확한 것 같습니다. –