File tree Expand file tree Collapse file tree 5 files changed +91
-99
lines changed Expand file tree Collapse file tree 5 files changed +91
-99
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments