Skip to content

Run teardown once after reruns#205

Merged
icemac merged 4 commits intopytest-dev:masterfrom
lukasNebr:fix_session_fixtures
Feb 9, 2023
Merged

Run teardown once after reruns#205
icemac merged 4 commits intopytest-dev:masterfrom
lukasNebr:fix_session_fixtures

Conversation

@lukasNebr
Copy link
Copy Markdown
Contributor

@lukasNebr lukasNebr commented Feb 7, 2023

Fixes #51

Teardown of session, class, ... scoped fixture will be executed once after rerunning tests.

Used pytest version: 7.2.1

@lukasNebr lukasNebr marked this pull request as ready for review February 7, 2023 20:55
@icemac
Copy link
Copy Markdown
Contributor

icemac commented Feb 8, 2023

Thank you for this PR. Could you please additionally write a test which shows that the bug is now fixed?

@icemac
Copy link
Copy Markdown
Contributor

icemac commented Feb 8, 2023

Additionally tests seem to fail in pytest < 7. We currently support pytest >= 6.1.

@lukasNebr
Copy link
Copy Markdown
Contributor Author

I added a test to verify that the bug is fixed.

The implementation should now be compatible with pytest >= 6.1. I have forgotten the versions lower than 7 before. Sorry for that.

@icemac icemac requested a review from sallner February 8, 2023 19:12
@icemac
Copy link
Copy Markdown
Contributor

icemac commented Feb 8, 2023

Thank you for fixing the code and adding a test.

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.

Looks good from my perspective.

@icemac icemac merged commit b20fef5 into pytest-dev:master Feb 9, 2023
@icemac
Copy link
Copy Markdown
Contributor

icemac commented Feb 9, 2023

Thank you for (reviewing) this PR. 😃

@icemac
Copy link
Copy Markdown
Contributor

icemac commented Feb 9, 2023

I just released https://pypi.org/project/pytest-rerunfailures/11.1/ containing this fix.

@icemac
Copy link
Copy Markdown
Contributor

icemac commented Feb 10, 2023

These changes seem to cause #206. @lukasNebr Do you have an idea what could cause that error?

@lukasNebr
Copy link
Copy Markdown
Contributor Author

I have no idea whats the cause of this error. I tried to reproduce the behavior but I was not successful.

Basically the pytest_runtest_protocol hook starts the setup, calls the test method and executes the teardown. As a part of teardown the pytest_runtest_teardown hook will be executed.

As you can see in the code the execution_count for an item is set (line 563) before the setup is executed (line 572). So in the teardown the attribute should exist.

db = item.session.config.failures_db
item.execution_count = db.get_test_failures(item_location)
db.set_test_reruns(item_location, reruns)
if item.execution_count > reruns:
return True
need_to_run = True
while need_to_run:
item.execution_count += 1
item.ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
reports = runtestprotocol(item, nextitem=nextitem, log=False)

If you have also no idea what the cause of the error is I would implement a workaround to avoid the error.

@icemac
Copy link
Copy Markdown
Contributor

icemac commented Feb 14, 2023

Regarding to #206 the problem is caused if another plugin also defines pytest_runtest_protocol. Let's move the discussion how to solve this problem over there.

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.

Fixtures marked (scope='session') are run on every re-run

3 participants