모두 건너뛰고 시험 대신 꾸미는 각각의 테스트 기능@pytest.다.skipif()?

0

질문

나는 pytest 파일을 요구하는 환경을 설정합니다. 그래서 내가 다음과 같은 장식에 모든 기능이다.

@pytest.mark.skipif('password' not in os.environ,
                    reason='Environment variable "password" not set.')
def test_1(mock):
    ....

@pytest.mark.skipif('password' not in os.environ,
                    reason='Environment variable "password" not set.')
def test_2(mock):
    ....

@pytest.mark.skipif('password' not in os.environ,
                    reason='Environment variable "password" not set.')
def test_3(mock):
    ....

그것은 방법이 모두 건너뛰고 시험 대신에 꾸미는 각각의 테스트 기능입니까?

BTW,그것은 단지 건너뛰 테스트는 다음과 같은 메시지입니다. 그것은 방법으로 경고를 표시하려면 정보가 누락의 환경 변수가?

====== 25 skipped in 5.96s =======
pytest python
2021-11-24 03:54:51
1

최고의 응답

2

당신이 사용할 수 있는 설비와 autouse=True 는 건너 당신을 위해:

@pytest.fixture(autouse=True)
def skip_if_no_password():
    if 'password' in os.environ:
        yield
    else:
        pytest.skip('Environment variable "password" not set.')

또 다른 가능성을 테스트 클래스고에 마커를 아닌 클래스로에 의해 언급 누가복음 넬슨니다.

2021-11-24 12:10:19

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................