pytest-dev / pytest-dev/pytest-order

Parameterized tests cannot be ordered

Open
#55 12 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
210
Forks
17
Avg merge
16h 8m
Merged PRs (30d)
4

Description

Considering the example in pytest documentation:
https://pytest.org/en/6.2.x/example/parametrize.html#a-quick-port-of-testscenarios

If I include ordering:

scenario1 = ("basic", {"attribute": "value"})
scenario2 = ("advanced", {"attribute": "value2"})


class TestSampleWithScenarios:
    scenarios = [scenario1, scenario2]

    @pytest.mark.order(2)
    def test_demo1(self, attribute):
        assert isinstance(attribute, str)

    @pytest.mark.order(1)
    def test_demo2(self, attribute):
        assert isinstance(attribute, str)

I would expect this order:

test_scenarios.py::TestSampleWithScenarios::test_demo2[basic] PASSED     [ 25%]
test_scenarios.py::TestSampleWithScenarios::test_demo1[basic] PASSED     [ 50%]
test_scenarios.py::TestSampleWithScenarios::test_demo2[advanced] PASSED  [ 75%]
test_scenarios.py::TestSampleWithScenarios::test_demo1[advanced] PASSED  [100%]

But I get instead:

test_scenarios.py::TestSampleWithScenarios::test_demo2[basic] PASSED     [ 25%]
test_scenarios.py::TestSampleWithScenarios::test_demo2[advanced] PASSED  [ 50%]
test_scenarios.py::TestSampleWithScenarios::test_demo1[basic] PASSED     [ 75%]
test_scenarios.py::TestSampleWithScenarios::test_demo1[advanced] PASSED  [100%]

I have tried with --order-scope=class and --order-group-scope=class but they dont fix this.

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

Start with the linked pytest parametrization example and reproduce it using the shown --order-scope=class and --order-group-scope=class options. Trace how the parametrized scenarios are collected and ordered; done means the class-scoped run produces demo2[basic], demo1[basic], demo2[advanced], demo1[advanced], with regression coverage for that ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.