Skip to content

added rerun_except option#180

Merged
sallner merged 6 commits intopytest-dev:masterfrom
dheepan2:rerun_except
Feb 21, 2022
Merged

added rerun_except option#180
sallner merged 6 commits intopytest-dev:masterfrom
dheepan2:rerun_except

Conversation

@dheepan2
Copy link
Copy Markdown
Contributor

Added option support to rerun-except a particular Error/Exception.
Similar to rerun_only.

#179 (comment)

@sallner
Copy link
Copy Markdown
Member

sallner commented Feb 19, 2022

Hello @dheepan2, thank you for your contribution.

This looks like a nice addition to the options, although I think, this can already be accomplished in most cases with the --only-run argument.

To get this PR forward it still needs some tests like

@pytest.mark.parametrize(
"only_rerun_texts, should_rerun",
[
(["AssertionError"], True),
(["Assertion*"], True),
(["Assertion"], True),
(["ValueError"], False),
([""], True),
(["AssertionError: "], True),
(["AssertionError: ERR"], True),
(["ERR"], True),
(["AssertionError,ValueError"], False),
(["AssertionError ValueError"], False),
(["AssertionError", "ValueError"], True),
],
)
def test_only_rerun_flag(testdir, only_rerun_texts, should_rerun):
testdir.makepyfile('def test_only_rerun(): raise AssertionError("ERR")')
num_failed = 1
num_passed = 0
num_reruns = 1
num_reruns_actual = num_reruns if should_rerun else 0
pytest_args = ["--reruns", str(num_reruns)]
for only_rerun_text in only_rerun_texts:
pytest_args.extend(["--only-rerun", only_rerun_text])
result = testdir.runpytest(*pytest_args)
assert_outcomes(
result, passed=num_passed, failed=num_failed, rerun=num_reruns_actual
)
but probably also for different errors raised. Additionally a changelog entry is needed.

@sallner sallner self-requested a review February 19, 2022 06:12
@dheepan2
Copy link
Copy Markdown
Contributor Author

Hello @dheepan2, thank you for your contribution.

This looks like a nice addition to the options, although I think, this can already be accomplished in most cases with the --only-run argument.

To get this PR forward it still needs some tests like

@pytest.mark.parametrize(
"only_rerun_texts, should_rerun",
[
(["AssertionError"], True),
(["Assertion*"], True),
(["Assertion"], True),
(["ValueError"], False),
([""], True),
(["AssertionError: "], True),
(["AssertionError: ERR"], True),
(["ERR"], True),
(["AssertionError,ValueError"], False),
(["AssertionError ValueError"], False),
(["AssertionError", "ValueError"], True),
],
)
def test_only_rerun_flag(testdir, only_rerun_texts, should_rerun):
testdir.makepyfile('def test_only_rerun(): raise AssertionError("ERR")')
num_failed = 1
num_passed = 0
num_reruns = 1
num_reruns_actual = num_reruns if should_rerun else 0
pytest_args = ["--reruns", str(num_reruns)]
for only_rerun_text in only_rerun_texts:
pytest_args.extend(["--only-rerun", only_rerun_text])
result = testdir.runpytest(*pytest_args)
assert_outcomes(
result, passed=num_passed, failed=num_failed, rerun=num_reruns_actual
)

but probably also for different errors raised. Additionally a changelog entry is needed.

@dheepan2 dheepan2 closed this Feb 19, 2022
@dheepan2 dheepan2 reopened this Feb 19, 2022
@dheepan2
Copy link
Copy Markdown
Contributor Author

Hello @dheepan2, thank you for your contribution.
This looks like a nice addition to the options, although I think, this can already be accomplished in most cases with the --only-run argument.
To get this PR forward it still needs some tests like

@pytest.mark.parametrize(
"only_rerun_texts, should_rerun",
[
(["AssertionError"], True),
(["Assertion*"], True),
(["Assertion"], True),
(["ValueError"], False),
([""], True),
(["AssertionError: "], True),
(["AssertionError: ERR"], True),
(["ERR"], True),
(["AssertionError,ValueError"], False),
(["AssertionError ValueError"], False),
(["AssertionError", "ValueError"], True),
],
)
def test_only_rerun_flag(testdir, only_rerun_texts, should_rerun):
testdir.makepyfile('def test_only_rerun(): raise AssertionError("ERR")')
num_failed = 1
num_passed = 0
num_reruns = 1
num_reruns_actual = num_reruns if should_rerun else 0
pytest_args = ["--reruns", str(num_reruns)]
for only_rerun_text in only_rerun_texts:
pytest_args.extend(["--only-rerun", only_rerun_text])
result = testdir.runpytest(*pytest_args)
assert_outcomes(
result, passed=num_passed, failed=num_failed, rerun=num_reruns_actual
)

but probably also for different errors raised. Additionally a changelog entry is needed.

Yeah, you are right, but in certain cases with infra issues or system issues(we will not be aware of the run time Error/Exception type), during those scenarios I want the pytest to rerun any Errors other than an AssertionError.

I have added the test and updated the changelog too.

@sallner sallner merged commit 807095f into pytest-dev:master Feb 21, 2022
@sallner
Copy link
Copy Markdown
Member

sallner commented Feb 21, 2022

@dheepan2 Thank you for also putting in the effort and clean up the readme.

Copy link
Copy Markdown
Member

@sallner sallner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants