File: test_ordinal.py

package info (click to toggle)
pytest-order 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 600 kB
  • sloc: python: 3,483; makefile: 159; sh: 13
file content (31 lines) | stat: -rw-r--r-- 846 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from unittest import mock
from textwrap import dedent

import pytest
from perf_tests.util import TimedSorter

pytest_plugins = ["pytester"]


@pytest.fixture
def fixture_path_ordinal(testdir):
    for i_mod in range(10):
        test_name = testdir.tmpdir.join(f"test_performance{i_mod}.py")
        test_contents = "import pytest\n"
        for i in range(100):
            test_contents += dedent(
                f"""
                @pytest.mark.order({50 - i})
                def test_{i}():
                    assert True
                """
            )
        test_name.write(test_contents)
    yield testdir


@mock.patch("pytest_order.plugin.Sorter", TimedSorter)
def test_performance_ordinal(fixture_path_ordinal):
    TimedSorter.nr_marks = 1000
    fixture_path_ordinal.runpytest("--quiet")
    assert TimedSorter.elapsed < 0.02