pytest-dev / pytest-dev/pytest

Difference in call sequence for teardown between fixture class decoration and through usefixtrue field of ini file.

Open
#8,427 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: fixtures
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

As suggested in the discussion 8402 i create the following issue.

As a summary :

  • There is a difference in the call order regarding teardown when:
    • Your test class is decorated with a fixture using the pytest marker usefixtures
    • In the ini file when using the field usefixtures to specify the same fixture

What is seen:

  • In the case of the fixture decorated class, the fixture teardown is called at the begining of the teardown_method of the test class (which is the expected behavior)
  • In the case of the ini file, the fixture teardown seems to be called at the end of the teardown_method of the test class.

Behavior seen with :

  • python2.7 && pytest 4.6.11
  • python3.8 && pytest 6.2.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with discussion 8402 and reproduce the teardown-order difference described for class-level and ini-file usefixtures configuration using the reported Python and pytest versions. Trace the fixture setup and teardown paths involved; done means both configurations produce the expected, consistent ordering around teardown_method.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.