1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
# Copyright 2021-2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
#
"""
Test the ``@pytest.mark.skip_unless_on_linux`` marker.
"""
import sys
from unittest import mock
import pytest
pytestmark = [
pytest.mark.skipif(
sys.platform.startswith("win")
and sys.version_info >= (3, 8)
and sys.version_info < (3, 10),
reason="PyTest's capture and pytester.runpytest_inprocess looks broken on Windows and Py(>3.8,<3.10)",
),
]
def test_skipped(pytester):
pytester.makepyfile(
"""
import pytest
@pytest.mark.skip_unless_on_linux
def test_one():
assert True
"""
)
return_value = False
with mock.patch("pytestskipmarkers.utils.platform.is_linux", return_value=return_value):
res = pytester.runpytest_inprocess()
res.assert_outcomes(skipped=1)
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
def test_not_skipped(pytester):
pytester.makepyfile(
"""
import pytest
@pytest.mark.skip_unless_on_linux
def test_one():
assert True
"""
)
return_value = True
with mock.patch("pytestskipmarkers.utils.platform.is_linux", return_value=return_value):
res = pytester.runpytest_inprocess()
res.assert_outcomes(passed=1)
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
def test_skip_reason(pytester):
pytester.makepyfile(
"""
import pytest
@pytest.mark.skip_unless_on_linux(reason='Because!')
def test_one():
assert True
"""
)
return_value = False
with mock.patch("pytestskipmarkers.utils.platform.is_linux", return_value=return_value):
res = pytester.runpytest_inprocess("-ra", "-s", "-vv")
res.assert_outcomes(skipped=1)
res.stdout.fnmatch_lines(["SKIPPED * test_skip_reason.py:*: Because!"])
|