pytest-dev / pytest-dev/pytest-django

setUpClass is not called with either pytest>4.1.1 or pytest-django>3.4.6

Open
#753 19 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

This is similar to #710 and #624

These 2 combinations work for me on python2:

pytest==4.1.1
pytest-django==3.5.1

pytest==4.6.4
pytest-django==3.4.6

But I cannot run the 2 libraries together on their latest release as in one test method out of a test suite with more than 5000 unit tests it occurs that the setUpClass method for the one test is then not called. The setUpClass is defined in a widely used mixin class (not inheriting from a TestClass base) and works everywhere else.

It is really weird how two testcases seem to disturb one another but it does not make any sense to me:

Here a quick description of my scenario:

mixin.py
class MyMixin() with a setUpClass

firstmodule.py:
class FirstTestCase(MyMixin) with test_foo

secondmodule.py

from firstmodule import FirstTestCase <---- when commenting this out my setUpClass gets run again for FirstTestCase::test_foo
class OtherModulesTestCase(FirstTestCase)

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 by reproducing the issue with the stated pytest and pytest-django version combinations, using mixin.py, firstmodule.py, and secondmodule.py as the minimal scenario. Trace how importing FirstTestCase and subclassing it affects setUpClass; done means the method is reliably called for FirstTestCase::test_foo in the affected combinations.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.