pytest-dev / pytest-dev/pytest-xdist

looponfail reruns passing tests along with failing if pytest is invoked from a subdirectory

Open
#730 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.9k
Forks
287
Avg merge
9h 30m
Merged PRs (30d)
2

Description

When there are failing tests, running pytest --looponfail is supposed to rerun only the previously failing tests until all tests pass:

--looponfail: run your tests repeatedly in a subprocess. After each run pytest waits until a file in your project changes and then re-runs the previously failing tests. This is repeated until all tests pass after which again a full run is performed.

However, if pytest is invoked from a subdirectory of the project (i.e. a directory below where pytest.ini/pyproject.toml are defined), --looponfail reruns all tests, including those that previously passed, on each code change.

For example, with this project structure:

project/
   | - pytest.ini
   | - subfolder/
            |- tests/
                  |- __init__.py
                  |- test_code.py

Invoking pytest --looponfail from within the project/ directory works as expected. However, invoking pytest --looponfail from within project/subfolder/ will repeat all passing tests as well as failing tests on every change.

Removing the pytest.ini file, or removing the [tool.pytest.ini_options] section from pyproject.toml, restores expected --looponfail behavior; presumably because pytest now considers subfolder/ to be the project root.

This behavior observed with:

  • python 3.9.5
  • pytest 6.2.5
  • pytest-xdist 2.4.0

Contributor guide

No contributing guide indexed for this repository

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

Reproduce the issue by running pytest --looponfail from the project root and from subfolder/, with pytest.ini or the [tool.pytest.ini_options] section in pyproject.toml. Start by tracing how looponfail determines the project root and tracks previously failing tests. Done means changes from the subdirectory rerun only the failing tests, not tests that already passed.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.