Skip to content

Populate tests from module-level fixture #9945

Answered by nicoddemus
AndySemenov asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @AndySemenov,

A normal pytest session is designed to execute two separate stages:

  1. Collection, where we find out which tests exist (along with other conftest.py files discovered while we search the file system). At this stage pytest_generate_tests kicks in for each module it is defined, and can generate more tests. At this point we also discover fixtures, their scopes, and their visibility to each test (no fixture code is executed yet).
  2. Test run: at this stage, for each collected test, we execute it, which happens in 3 steps: setup, call, and teardown. During setup, each fixture requested by the test is executed, with the return value injected into the test function.

Under this design…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@AndySemenov
Comment options

@nicoddemus
Comment options

@AndySemenov
Comment options

Answer selected by AndySemenov
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