Skip to content

Commit 497b29d

Browse files
Bastian-KrauseEmantor
authored andcommitted
tests/test_flags: add test_lg_feature_unexpected_args
Tests if the appropriate pytest.UsageErrors are raised for calls to @pytest.mark.lg_feature() with unexpected arguments. Signed-off-by: Bastian Krause <bst@pengutronix.de>
1 parent 1a749b3 commit 497b29d

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tests/test_flags.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,33 @@ def test(self, env):
142142
spawn.expect(pexpect.EOF)
143143
spawn.close()
144144
assert spawn.exitstatus == 0
145+
146+
@pytest.mark.parametrize(
147+
"marker_args_str,error",
148+
[
149+
("", "Unexpected number of args/kwargs"),
150+
("'too', 'many'", "Unexpected number of args/kwargs"),
151+
("{'foo': 'bar'}", "Unsupported 'features' argument type"),
152+
],
153+
ids=["no args", "too many args", "unsupported arg type"]
154+
)
155+
def test_lg_feature_unexpected_args(tmpdir, env_feature_config, marker_args_str, error):
156+
# features do not matter here, simply generate a valid env config
157+
conf = env_feature_config([])
158+
test = tmpdir.join("test.py")
159+
test.write(
160+
f"""
161+
import pytest
162+
163+
@pytest.mark.lg_feature({marker_args_str})
164+
def test(self, env):
165+
assert True
166+
"""
167+
)
168+
169+
with pexpect.spawn(f'pytest --lg-env {conf} {test}') as spawn:
170+
spawn.expect(error)
171+
spawn.expect(pexpect.EOF)
172+
spawn.close()
173+
# pytest command line usage error leads to exit code 4
174+
assert spawn.exitstatus == 4

0 commit comments

Comments
 (0)