pytest (Python 3)를 사용하여 일부 하드웨어 장치 (전자 장치)를 테스트하는 테스트 제품군을 성공적으로 실행하고 있습니다. 이 테스트의 하위 집합 인 경우 테스터가 하드웨어 배열을 변경하고 나중에 다시 변경해야합니다. 내 접근 방식은 두 input
호출로, (별도의 모듈에있는 모든 것이) 문제의 시험에 부착 된 모듈 수준의 비품을 사용하는 것이었다 :pytest가 (수동) 사용자 작업을 기다리는 방법?
@pytest.fixture(scope="module")
def disconnect_component():
input('Disconnect component, then press enter')
yield # At this point all the tests with this fixture are run
input('Connect component again, then press enter')
이 프로그램을 실행할 때, 나는 OSError: reading from stdin while output is captured
를 얻을. 나는 pytest를 --capture=no
으로 호출함으로써이를 피할 수 있으며, 내 접근법이 작동한다는 것을 확인했습니다. 즉, 문제의 테스트 하위 집합에서 첫 번째 쿼리를 얻었고, 두 번째 쿼리는 실행 한 후 첫 번째 쿼리를 얻음을 의미합니다.
큰 결점은 다른 테스트의 일부가 의존하는 전체 테스트 세트에 대한 stdin/stderr 캡처를 비활성화한다는 것입니다.
나는이@pytest.fixture(scope="module")
def disconnect_component(capsys):
with capsys.disabled():
input('Disconnect component, then press enter')
yield # At this point all the tests with this fixture are run
input('Connect component again, then press enter')
처럼 capsys.disabled
(docs)를 사용하려하지만이를 실행할 때 나는 ScopeMismatch: You tried to access the 'function' scoped fixture 'capsys' with a 'module' scoped request object, involved factories
를 얻을.
input
이외의 다른 방법으로 사용자 동작을 기다리는 pyTest를 만들 수 있습니까? 그렇지 않은 경우, 위의 조명기를 사용하여 테스트를 캡처하는 기능을 비활성화 할 수 있습니까?
@pytest.fixture(scope="module")
def disconnect_component(pytestconfig):
capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')
capmanager.suspendcapture(in_=True)
input('Disconnect component, then press enter')
capmanager.resumecapture()
yield # At this point all the tests with this fixture are run
capmanager.suspendcapture(in_=True)
input('Connect component again, then press enter')
capmanager.resumecapture()
이 완벽 최대한 멀리 볼 수 작동합니다
"표준 입력이 자동으로 테스트에 필요하지 않습니다"입니다의 어떤 부분에서이 작업을 수행 할 수 있습니다 stoneage (Fortran 77로 작성). 나는 근원이 없기 때문에 그 (것)들을 다시 쓸 수 없다. 그래서 Popen을 사용하여 파이썬 코드를 작성하여이 오래된 exe를 툴 체인에 붙입니다. 이 오래된 실행 파일은 사용자 입력에 크게 의존합니다. 이는 거의 "계속 입력하라"입니다. 당신의 대답은 나에게 subprocess.communicate를 통한 입력에서 파이프를 사용하고 전체 툴체인을 테스트하기 위해 pytest를 사용하는 opertunity를 제공합니다. – Hatatister
유용한 정보를 제공합니다. 접착제 언어로 사용되는 파이썬이 흔들립니다! :-D – Christoph