Skip to content

Commit 56432c0

Browse files
committed
Change performance tests to only check our code
- should make it more reliable - tests are Python 3 only
1 parent 907fca2 commit 56432c0

File tree

5 files changed

+91
-99
lines changed

5 files changed

+91
-99
lines changed

perf_tests/__init__.py

Whitespace-only changes.

perf_tests/test_order.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

perf_tests/test_ordinal.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import shutil
3+
from unittest import mock
4+
5+
import pytest
6+
import pytest_order
7+
from perf_tests.util import TimedSorter
8+
from tests.utils import write_test
9+
10+
11+
@pytest.fixture
12+
def fixture_path_ordinal(tmpdir_factory):
13+
fixture_path = str(tmpdir_factory.mktemp("ordinal_perf"))
14+
for module_index in range(10):
15+
testname = os.path.join(
16+
fixture_path, "test_performance{}.py".format(module_index))
17+
test_contents = """
18+
import pytest
19+
"""
20+
for i in range(100):
21+
test_contents += """
22+
@pytest.mark.order({})
23+
def test_{}():
24+
assert True
25+
""".format(50 - i, i)
26+
write_test(testname, test_contents)
27+
yield fixture_path
28+
shutil.rmtree(fixture_path, ignore_errors=True)
29+
30+
31+
@mock.patch("pytest_order.Sorter", TimedSorter)
32+
def test_performance_ordinal(fixture_path_ordinal):
33+
args = [fixture_path_ordinal]
34+
pytest.main(args, [pytest_order])
35+
assert TimedSorter.elapsed < 0.02

perf_tests/test_relative.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import shutil
3+
from unittest import mock
4+
5+
import pytest
6+
7+
import pytest_order
8+
from perf_tests.util import TimedSorter
9+
from tests.utils import write_test
10+
11+
12+
@pytest.fixture
13+
def fixture_path_relative(tmpdir_factory):
14+
fixture_path = str(tmpdir_factory.mktemp("relative_perf"))
15+
for module_index in range(10):
16+
testname = os.path.join(
17+
fixture_path, "test_relative_perf{}.py".format(module_index))
18+
test_contents = """
19+
import pytest
20+
"""
21+
for i in range(90):
22+
test_contents += """
23+
@pytest.mark.order(after="test_{}")
24+
def test_{}():
25+
assert True
26+
""".format(i + 10, i)
27+
for i in range(10):
28+
test_contents += """
29+
def test_{}():
30+
assert True
31+
""".format(i + 90)
32+
write_test(testname, test_contents)
33+
yield fixture_path
34+
shutil.rmtree(fixture_path, ignore_errors=True)
35+
36+
37+
@mock.patch("pytest_order.Sorter", TimedSorter)
38+
def test_performance_relative(fixture_path_relative):
39+
args = [fixture_path_relative]
40+
pytest.main(args, [pytest_order])
41+
assert TimedSorter.elapsed < 1.2

perf_tests/util.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import time
2+
3+
from pytest_order import Sorter
4+
5+
6+
class TimedSorter(Sorter):
7+
elapsed = 0
8+
9+
def sort_items(self):
10+
self.__class__.elapsed = 0
11+
start_time = time.time()
12+
items = super().sort_items()
13+
self.__class__.elapsed += time.time() - start_time
14+
print("Time per test: {:.3f} ms".format(self.__class__.elapsed))
15+
return items

0 commit comments

Comments
 (0)