Skip to content

Commit 6672ddc

Browse files
committed
Increase code coverage
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
1 parent 45a2b45 commit 6672ddc

29 files changed

Lines changed: 763 additions & 3 deletions

tests/functional/test_skip_if_binaries_missing.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,61 @@ def test_one():
7777
res = pytester.runpytest_subprocess("-ra", "-vv")
7878
res.assert_outcomes(passed=1)
7979
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
80+
81+
82+
def test_single_non_existing_with_deprecated_message(pytester, python_binary):
83+
pytester.makepyfile(
84+
"""
85+
import pytest
86+
87+
@pytest.mark.skip_if_binaries_missing("python9", message="Dam!")
88+
def test_one():
89+
assert True
90+
"""
91+
)
92+
res = pytester.runpytest_subprocess("-ra", "-vv")
93+
res.assert_outcomes(skipped=1)
94+
res.stdout.fnmatch_lines(
95+
[
96+
"""*: PytestWarning: Please stop passing 'message="Dam!"' and instead pass 'reason="Dam!"'"""
97+
]
98+
)
99+
100+
101+
def test_no_arguments(pytester):
102+
pytester.makepyfile(
103+
"""
104+
import pytest
105+
106+
@pytest.mark.skip_if_binaries_missing
107+
def test_one():
108+
assert True
109+
"""
110+
)
111+
res = pytester.runpytest()
112+
res.assert_outcomes(errors=1)
113+
res.stdout.fnmatch_lines(
114+
[
115+
"*UsageError: The 'skip_if_binaries_missing' marker needs at least one binary name to be passed"
116+
]
117+
)
118+
119+
120+
def test_multiple_binaries_as_single_list_arg(pytester):
121+
pytester.makepyfile(
122+
"""
123+
import pytest
124+
125+
@pytest.mark.skip_if_binaries_missing(["python", "python9"])
126+
def test_one():
127+
assert True
128+
"""
129+
)
130+
res = pytester.runpytest()
131+
res.assert_outcomes(errors=1)
132+
res.stdout.fnmatch_lines(
133+
[
134+
"*UsageError: The 'skip_if_binaries_missing' marker only accepts strings as arguments. If you are "
135+
"trying to pass multiple binaries, each binary should be an separate argument."
136+
]
137+
)

tests/functional/test_skip_on_aarch64.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,28 @@ def test_one():
6565
res = pytester.runpytest_inprocess("-ra", "-s", "-vv")
6666
res.assert_outcomes(skipped=1)
6767
res.stdout.fnmatch_lines(["SKIPPED * test_skip_reason.py:*: Because!"])
68+
69+
70+
def test_error_on_args_or_kwargs(pytester):
71+
pytester.makepyfile(
72+
"""
73+
import pytest
74+
75+
@pytest.mark.skip_on_aarch64("arg")
76+
def test_one():
77+
assert True
78+
79+
@pytest.mark.skip_on_aarch64(kwarg="arg")
80+
def test_two():
81+
assert True
82+
"""
83+
)
84+
res = pytester.runpytest()
85+
res.assert_outcomes(errors=2)
86+
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
87+
res.stdout.fnmatch_lines(
88+
[
89+
"*UsageError: The skip_on_aarch64 marker does not accept any arguments",
90+
"*UsageError: The skip_on_aarch64 marker only accepts 'reason' as a keyword argument.",
91+
]
92+
)

tests/functional/test_skip_on_aix.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,28 @@ def test_one():
6969
res = pytester.runpytest_inprocess("-ra", "-s", "-vv")
7070
res.assert_outcomes(skipped=1)
7171
res.stdout.fnmatch_lines(["SKIPPED * test_skip_reason.py:*: Because!"])
72+
73+
74+
def test_error_on_args_or_kwargs(pytester):
75+
pytester.makepyfile(
76+
"""
77+
import pytest
78+
79+
@pytest.mark.skip_on_aix("arg")
80+
def test_one():
81+
assert True
82+
83+
@pytest.mark.skip_on_aix(kwarg="arg")
84+
def test_two():
85+
assert True
86+
"""
87+
)
88+
res = pytester.runpytest()
89+
res.assert_outcomes(errors=2)
90+
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
91+
res.stdout.fnmatch_lines(
92+
[
93+
"*UsageError: The skip_on_aix marker does not accept any arguments",
94+
"*UsageError: The skip_on_aix marker only accepts 'reason' as a keyword argument.",
95+
]
96+
)

tests/functional/test_skip_on_darwin.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,28 @@ def test_one():
6868
res = pytester.runpytest_inprocess("-ra", "-s", "-vv")
6969
res.assert_outcomes(skipped=1)
7070
res.stdout.fnmatch_lines(["SKIPPED * test_skip_reason.py:*: Because!"])
71+
72+
73+
def test_error_on_args_or_kwargs(pytester):
74+
pytester.makepyfile(
75+
"""
76+
import pytest
77+
78+
@pytest.mark.skip_on_darwin("arg")
79+
def test_one():
80+
assert True
81+
82+
@pytest.mark.skip_on_darwin(kwarg="arg")
83+
def test_two():
84+
assert True
85+
"""
86+
)
87+
res = pytester.runpytest()
88+
res.assert_outcomes(errors=2)
89+
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
90+
res.stdout.fnmatch_lines(
91+
[
92+
"*UsageError: The skip_on_darwin marker does not accept any arguments",
93+
"*UsageError: The skip_on_darwin marker only accepts 'reason' as a keyword argument.",
94+
]
95+
)

tests/functional/test_skip_on_env.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,65 @@ def test_one():
5050
res = pytester.runpytest_inprocess()
5151
res.assert_outcomes(passed=1)
5252
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
53+
54+
55+
def test_error_on_missing_arg(pytester):
56+
pytester.makepyfile(
57+
"""
58+
import pytest
59+
60+
@pytest.mark.skip_on_env
61+
def test_one():
62+
assert True
63+
"""
64+
)
65+
res = pytester.runpytest()
66+
res.assert_outcomes(errors=1)
67+
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
68+
res.stdout.fnmatch_lines(
69+
[
70+
"*UsageError: The 'skip_on_env' marker needs at least one argument to be passed, "
71+
"the environment variable name.",
72+
]
73+
)
74+
75+
76+
def test_error_on_multiple_args(pytester):
77+
pytester.makepyfile(
78+
"""
79+
import pytest
80+
81+
@pytest.mark.skip_on_env("FOOBAR", "BARFOO", eq="2")
82+
def test_one():
83+
assert True
84+
"""
85+
)
86+
res = pytester.runpytest()
87+
res.assert_outcomes(errors=1)
88+
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
89+
res.stdout.fnmatch_lines(
90+
[
91+
"*UsageError: The 'skip_on_env' only accepts one argument, the environment variable name.",
92+
]
93+
)
94+
95+
96+
def test_error_on_bad_kwargs(pytester):
97+
pytester.makepyfile(
98+
"""
99+
import pytest
100+
101+
@pytest.mark.skip_on_env("FOOBAR", eq="2", bar=True)
102+
def test_one():
103+
assert True
104+
"""
105+
)
106+
res = pytester.runpytest()
107+
res.assert_outcomes(errors=1)
108+
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
109+
res.stdout.fnmatch_lines(
110+
[
111+
"*UsageError: The 'skip_on_env' marker only accepts 'present', 'eq', 'ne' and 'reason' "
112+
"as keyword arguments.",
113+
]
114+
)

tests/functional/test_skip_on_freebsd.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,28 @@ def test_one():
6868
res = pytester.runpytest_inprocess("-ra", "-s", "-vv")
6969
res.assert_outcomes(skipped=1)
7070
res.stdout.fnmatch_lines(["SKIPPED * test_skip_reason.py:*: Because!"])
71+
72+
73+
def test_error_on_args_or_kwargs(pytester):
74+
pytester.makepyfile(
75+
"""
76+
import pytest
77+
78+
@pytest.mark.skip_on_freebsd("arg")
79+
def test_one():
80+
assert True
81+
82+
@pytest.mark.skip_on_freebsd(kwarg="arg")
83+
def test_two():
84+
assert True
85+
"""
86+
)
87+
res = pytester.runpytest()
88+
res.assert_outcomes(errors=2)
89+
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
90+
res.stdout.fnmatch_lines(
91+
[
92+
"*UsageError: The skip_on_freebsd marker does not accept any arguments",
93+
"*UsageError: The skip_on_freebsd marker only accepts 'reason' as a keyword argument.",
94+
]
95+
)

tests/functional/test_skip_on_linux.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,28 @@ def test_one():
6868
res = pytester.runpytest_inprocess("-ra", "-s", "-vv")
6969
res.assert_outcomes(skipped=1)
7070
res.stdout.fnmatch_lines(["SKIPPED * test_skip_reason.py:*: Because!"])
71+
72+
73+
def test_error_on_args_or_kwargs(pytester):
74+
pytester.makepyfile(
75+
"""
76+
import pytest
77+
78+
@pytest.mark.skip_on_linux("arg")
79+
def test_one():
80+
assert True
81+
82+
@pytest.mark.skip_on_linux(kwarg="arg")
83+
def test_two():
84+
assert True
85+
"""
86+
)
87+
res = pytester.runpytest()
88+
res.assert_outcomes(errors=2)
89+
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
90+
res.stdout.fnmatch_lines(
91+
[
92+
"*UsageError: The skip_on_linux marker does not accept any arguments",
93+
"*UsageError: The skip_on_linux marker only accepts 'reason' as a keyword argument.",
94+
]
95+
)

tests/functional/test_skip_on_netbsd.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,28 @@ def test_one():
6868
res = pytester.runpytest_inprocess("-ra", "-s", "-vv")
6969
res.assert_outcomes(skipped=1)
7070
res.stdout.fnmatch_lines(["SKIPPED * test_skip_reason.py:*: Because!"])
71+
72+
73+
def test_error_on_args_or_kwargs(pytester):
74+
pytester.makepyfile(
75+
"""
76+
import pytest
77+
78+
@pytest.mark.skip_on_netbsd("arg")
79+
def test_one():
80+
assert True
81+
82+
@pytest.mark.skip_on_netbsd(kwarg="arg")
83+
def test_two():
84+
assert True
85+
"""
86+
)
87+
res = pytester.runpytest()
88+
res.assert_outcomes(errors=2)
89+
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
90+
res.stdout.fnmatch_lines(
91+
[
92+
"*UsageError: The skip_on_netbsd marker does not accept any arguments",
93+
"*UsageError: The skip_on_netbsd marker only accepts 'reason' as a keyword argument.",
94+
]
95+
)

tests/functional/test_skip_on_openbsd.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,28 @@ def test_one():
6868
res = pytester.runpytest_inprocess("-ra", "-s", "-vv")
6969
res.assert_outcomes(skipped=1)
7070
res.stdout.fnmatch_lines(["SKIPPED * test_skip_reason.py:*: Because!"])
71+
72+
73+
def test_error_on_args_or_kwargs(pytester):
74+
pytester.makepyfile(
75+
"""
76+
import pytest
77+
78+
@pytest.mark.skip_on_openbsd("arg")
79+
def test_one():
80+
assert True
81+
82+
@pytest.mark.skip_on_openbsd(kwarg="arg")
83+
def test_two():
84+
assert True
85+
"""
86+
)
87+
res = pytester.runpytest()
88+
res.assert_outcomes(errors=2)
89+
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
90+
res.stdout.fnmatch_lines(
91+
[
92+
"*UsageError: The skip_on_openbsd marker does not accept any arguments",
93+
"*UsageError: The skip_on_openbsd marker only accepts 'reason' as a keyword argument.",
94+
]
95+
)

tests/functional/test_skip_on_photonos.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,28 @@ def test_one():
6565
res = pytester.runpytest_inprocess("-ra", "-s", "-vv")
6666
res.assert_outcomes(skipped=1)
6767
res.stdout.fnmatch_lines(["SKIPPED * test_skip_reason.py:*: Because!"])
68+
69+
70+
def test_error_on_args_or_kwargs(pytester):
71+
pytester.makepyfile(
72+
"""
73+
import pytest
74+
75+
@pytest.mark.skip_on_photonos("arg")
76+
def test_one():
77+
assert True
78+
79+
@pytest.mark.skip_on_photonos(kwarg="arg")
80+
def test_two():
81+
assert True
82+
"""
83+
)
84+
res = pytester.runpytest()
85+
res.assert_outcomes(errors=2)
86+
res.stdout.no_fnmatch_line("*PytestUnknownMarkWarning*")
87+
res.stdout.fnmatch_lines(
88+
[
89+
"*UsageError: The skip_on_photonos marker does not accept any arguments",
90+
"*UsageError: The skip_on_photonos marker only accepts 'reason' as a keyword argument.",
91+
]
92+
)

0 commit comments

Comments
 (0)