Skip to content

Commit

Permalink
Error if @fail_slow is not given exactly one argument
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Aug 13, 2022
1 parent 7f650f3 commit df8fe67
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v0.3.0 (in development)
-----------------------
- The `@pytest.mark.fail_slow()` marker now errors if not given exactly one
argument. Previously, it would either use the first argument or, if no
arguments were given, it would be ignored.

v0.2.0 (2022-04-25)
-------------------
- Test against pytest 7
Expand Down
8 changes: 6 additions & 2 deletions src/pytest_fail_slow.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
Visit <https://github.com/jwodder/pytest-fail-slow> for more information.
"""

__version__ = "0.2.0"
__version__ = "0.3.0.dev1"
__author__ = "John Thorvald Wodder II"
__author_email__ = "pytest-fail-slow@varonathe.org"
__license__ = "MIT"
Expand Down Expand Up @@ -109,7 +109,11 @@ def pytest_addoption(parser) -> None:
def pytest_runtest_makereport(item, call):
report = (yield).get_result()
mark = item.get_closest_marker("fail_slow")
if mark is not None and len(mark.args) > 0:
if mark is not None:
if len(mark.args) != 1:
raise pytest.UsageError(
"@pytest.mark.fail_slow() takes exactly one argument"
)
timeout = parse_duration(mark.args[0])
else:
timeout = item.config.getoption("--fail-slow")
Expand Down
19 changes: 19 additions & 0 deletions test/test_fail_slow.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,22 @@ def test_fail_slow_threshold(
)
else:
result.stdout.no_fnmatch_line("*Test passed but took too long to run*")


@pytest.mark.parametrize("args", ["", "42, 'foo'"])
def test_fail_slow_marker_bad_args(pytester, args: str) -> None:
pytester.makepyfile(
test_func=(
"import pytest\n"
"\n"
f"@pytest.mark.fail_slow({args})\n"
"def test_func():\n"
" assert 2 + 2 == 4\n"
)
)
result = pytester.runpytest()
result.assert_outcomes()
result.stdout.no_fnmatch_line("?")
result.stderr.fnmatch_lines(
["ERROR: @pytest.mark.fail_slow() takes exactly one argument"]
)

0 comments on commit df8fe67

Please sign in to comment.