2017-12-07 31 views
1

py.test를 사용하여 테스트 목록 (약 5 개 항목)을 제외하고 싶습니다.py.test로 테스트 목록을 제외하고 명령 줄에서 제외 하시겠습니까?

이 목록을 명령 줄을 통해 py.test에 제공하고 싶습니다.

소스 수정을 피하고 싶습니다.

어떻게 수행하나요?

+0

당신이 argparse를 사용하여 시도? – IMCoins

+0

내 상황에 맞는 @IMCoins py.test는 명령 행 도구입니다. 나는이 문맥에서 파이썬 소스를 수정할 수 없다. argparse는 파이썬 라이브러리이기 때문에 여기서는 도움이되지 않는다고 생각합니다. – guettli

답변

4

참조 옵션은 -k입니다. 와

def test_spam(): 
    pass 

def test_ham(): 
    pass 

def test_eggs(): 
    pass 

호출의 pytest : 당신이 다음 테스트가있는 경우

pytest -v -k 'not spam and not ham' tests.py 

를 당신은 얻을 것이다 :

collected 3 items 

pytest_skip_tests.py::test_eggs PASSED    [100%] 

=================== 2 tests deselected =================== 
========= 1 passed, 2 deselected in 0.01 seconds ========= 
+0

니스, 나는 오늘 뭔가를 배웠다! –

+0

예, 작동합니다. 이 답변에 감사드립니다. – guettli

2

이가 conftest.py 파일을 생성하여 작업을 얻을 수 :

는 당신이 그것을 사용하는 것이
# content of conftest.py 

import pytest 
def pytest_addoption(parser): 
    parser.addoption("--skiplist", action="store_true", 
        default="", help="skip listed tests") 

def pytest_collection_modifyitems(config, items): 
    tests_to_skip = config.getoption("--skiplist") 
    if not tests_to_skip: 
     # --skiplist not given in cli, therefore move on 
     return 
    skip_listed = pytest.mark.skip(reason="included in --skiplist") 
    for item in items: 
     if item.name in tests_to_skip: 
      item.add_marker(skip_listed) 

: 당신은 항상 동일한 테스트를 건너 뛸 경우

$ pytest --skiplist test1 test2 

참고 목록이 정의 될 수를 conftest.

당신은 tests selecting expression를 사용할 수도 this useful link

+0

답변 해 주셔서 감사합니다. – guettli