Skip to content

Perform a teardown immediately after a session scoped setup fixture fails. #12420

Answered by EugeneBrod
EugeneBrod asked this question in Q&A
Discussion options

You must be logged in to vote

Problem
I wanted to create crashlogs immediately after failure in setup or test call. I wanted to generate crashlogs once for every fixture, whether session or function scoped. To generate crashlogs I needed the result of a reliable "base" fixture which is run first during test execution.

Solution
Define a "SessionControlBlock" class, which stores the result of the "base" fixture and a few methods for generating crashlogs. The class is assigned to the pytest's "session" object.

I then implemented the pytest_fixture_setup hook to

  1. save the result of the "base" fixture to the SessionControlBlock
  2. determine if a fixture raised an exception, generate a crashlog if it did

The pytest_make_repor…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@EugeneBrod
Comment options

Answer selected by EugeneBrod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants