pytest-dev / pytest-dev/pytest-xdist

Help - How to preserve parallelism also if there are tests that needs to be executed alone?

Open
#818 7 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

Every test needs to be atomic. Tests should not affect other tests. This is clear.
But there are conditions that are changed by test execution, and you cannot stop this.
I'm talking about counters.
For example, you have a totally indipendent test that increment a counter.
You have another test that check that this counter is increased correctly.
In order to test this counter increment, you make something that increment the counter and then you check the counter.
The problem is when by the parallelism also all other test increment the same counter, and you cannot handle this.

i make an example.

Your software handle a coffee machine.
You have a coffee cup counter.
You want to test that after a coffee is done, the counter decreased by one.
In order to make this test atomic, you

  1. get the number of coffee cup
  2. make a coffee
  3. test the number of coffee cup is one less before

No problem with this.

The problem is when using xdist every other test use another coffee cup.
Running in parallel, these test

  1. make a normal coffee
  2. make a long coffee
  3. check coffee cup counter

can be execute IN THE SAME TIME, so "check coffee cup counter" can fail because while the test makes a coffee to check the counter is decresed by one, another test is making a coffee decreasing the counter by one making the "check cofree cup counter" fails.

so the request can be to "mark" "check coffee cup counter" as to be executed alone, when all the other tests are done.

there is something wrong in my test suite implementation? any suggestion?

thanks

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

No source files, tests, or entry points are named. Start by reviewing pytest-xdist's parallel execution behavior and the reported counter interference, then determine whether exclusive test execution is a defined feature request or a test-suite design issue. Done would require a decided scope and documented expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.