Skip to content

Commit

Permalink
use verbosity count for trace limit rather than binary on off (#41)
Browse files Browse the repository at this point in the history
* use verbosity count for trace limit rather than binary on off

* added test for verbosity count
  • Loading branch information
str0zzapreti authored May 14, 2024
1 parent dc2123f commit cfb3a9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pytest_retry/retry_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class RetryManager:

def __init__(self) -> None:
self.reporter: ReportHandler = OfflineReporter()
self.trace_limit: Optional[int] = -1
self.trace_limit: Optional[int] = 1
self.node_stats: dict[str, dict] = {}
self.messages = (
" failed on attempt {attempt}! Retrying!\n\t",
Expand Down Expand Up @@ -298,9 +298,10 @@ def pytest_configure(config: pytest.Config) -> None:
"that the test is retried only on those exceptions, or excluding those exceptions. "
"Any statement which returns a bool can be used as a condition",
)
if config.getoption("verbose"):
# if pytest config has -v enabled, then don't limit traceback length
retry_manager.trace_limit = None
verbosity = config.getoption("verbose")
if verbosity:
# set trace limit according to verbosity count, or unlimited if 5
retry_manager.trace_limit = verbosity if verbosity < 5 else None
Defaults.configure(config)
Defaults.add("FILTERED_EXCEPTIONS", config.hook.pytest_set_filtered_exceptions() or [])
Defaults.add("EXCLUDED_EXCEPTIONS", config.hook.pytest_set_excluded_exceptions() or [])
Expand Down
16 changes: 16 additions & 0 deletions tests/test_retry_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,22 @@ def test_eventually_passes_once_more():
assert_outcomes(result, passed=2, failed=1, retried=2)


@mark.parametrize('verbosity', ['vv', 'vvv', 'vvvv'])
def test_stack_trace_depth_uses_verbosity_count(testdir, verbosity):
testdir.makepyfile(
"""
a = []
def test_eventually_passes():
a.append(1)
assert len(a) > 1
"""
)
result = testdir.runpytest("--retries", "1", f"-{verbosity}")

assert_outcomes(result, passed=1, retried=1)
assert len([line for line in result.outlines if line.startswith('\t File')]) == len(verbosity)


@mark.skipif(xdist_installed is False, reason="Only run if xdist is installed locally")
def test_xdist_reporting_compatability(testdir):
testdir.makepyfile(
Expand Down

0 comments on commit cfb3a9a

Please sign in to comment.