Skip to content

Commit 008d9b1

Browse files
author
Sergey Chipiga
committed
expand tests
1 parent 6bf512b commit 008d9b1

File tree

5 files changed

+135
-10
lines changed

5 files changed

+135
-10
lines changed

pytest_ordering/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
__author__ = '[email protected]'
4-
53
import pytest
64

75
orders_map = {
@@ -57,7 +55,7 @@ def pytest_collection_modifyitems(session, config, items):
5755
grouped_items.setdefault(order, []).append(item)
5856

5957
if grouped_items:
60-
unordered_items = grouped_items.pop(None) if None in grouped_items else None
58+
unordered_items = grouped_items.pop(None, None)
6159

6260
sorted_items = []
6361
prev_key = 0

pytest_ordering/author.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__author__ = '[email protected] <Frank Tobia>, ' \
2+
'[email protected] <Sergei Chipiga>'

pytest_ordering/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.0'
1+
__version__ = '0.4'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
install_requires=['pytest'],
2828
classifiers=[
29-
'Development Status :: Stable',
29+
'Development Status :: 4 - Beta',
3030
'Intended Audience :: Developers',
3131
'License :: OSI Approved :: MIT License',
3232
'Operating System :: POSIX',

tests/test_ordering.py

Lines changed: 130 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# -*- coding: utf-8 -*-
22

3-
__author__ = "[email protected]"
3+
import re
44

55
import pytest
6+
import pytest_ordering.author
7+
import pytest_ordering.version
68

79
pytest_plugins = ["pytester"]
810

@@ -28,7 +30,7 @@ def test_1(): pass
2830
def test_2(): pass
2931
"""
3032

31-
assert ['test_1', 'test_2'] == item_names_for(tests_content)
33+
assert item_names_for(tests_content) == ['test_1', 'test_2']
3234

3335

3436
def test_first_mark(item_names_for):
@@ -41,7 +43,7 @@ def test_1(): pass
4143
def test_2(): pass
4244
"""
4345

44-
assert ['test_2', 'test_1'] == item_names_for(tests_content)
46+
assert item_names_for(tests_content) == ['test_2', 'test_1']
4547

4648

4749
def test_last_mark(item_names_for):
@@ -54,7 +56,7 @@ def test_1(): pass
5456
def test_2(): pass
5557
"""
5658

57-
assert ['test_2', 'test_1'] == item_names_for(tests_content)
59+
assert item_names_for(tests_content) == ['test_2', 'test_1']
5860

5961

6062
def test_first_last_marks(item_names_for):
@@ -70,4 +72,127 @@ def test_2(): pass
7072
def test_3(): pass
7173
"""
7274

73-
assert ['test_2', 'test_3', 'test_1'] == item_names_for(tests_content)
75+
assert item_names_for(tests_content) == ['test_2', 'test_3', 'test_1']
76+
77+
78+
def test_order_marks(item_names_for):
79+
tests_content = """
80+
import pytest
81+
82+
@pytest.mark.run(order=-1)
83+
def test_1(): pass
84+
85+
@pytest.mark.run(order=-2)
86+
def test_2(): pass
87+
88+
@pytest.mark.run(order=1)
89+
def test_3(): pass
90+
"""
91+
92+
assert item_names_for(tests_content) == ['test_3', 'test_2', 'test_1']
93+
94+
95+
def test_first_mark_class(item_names_for):
96+
tests_content = """
97+
import pytest
98+
99+
def test_1(): pass
100+
101+
102+
@pytest.mark.first
103+
class TestSuite(object):
104+
105+
def test_3(self): pass
106+
107+
def test_2(self): pass
108+
109+
"""
110+
111+
assert item_names_for(tests_content) == ['test_3', 'test_2', 'test_1']
112+
113+
114+
def test_last_mark_class(item_names_for):
115+
tests_content = """
116+
import pytest
117+
118+
@pytest.mark.last
119+
class TestSuite(object):
120+
121+
def test_1(self): pass
122+
123+
def test_2(self): pass
124+
125+
126+
def test_3(): pass
127+
"""
128+
129+
assert item_names_for(tests_content) == ['test_3', 'test_1', 'test_2']
130+
131+
132+
def test_first_last_mark_class(item_names_for):
133+
tests_content = """
134+
import pytest
135+
136+
@pytest.mark.last
137+
class TestLast(object):
138+
139+
def test_1(self): pass
140+
141+
def test_2(self): pass
142+
143+
144+
def test_3(): pass
145+
146+
147+
@pytest.mark.first
148+
class TestFirst(object):
149+
150+
def test_4(self): pass
151+
152+
def test_5(self): pass
153+
154+
"""
155+
156+
assert item_names_for(tests_content) == ['test_4', 'test_5', 'test_3', 'test_1', 'test_2']
157+
158+
159+
def test_order_mark_class(item_names_for):
160+
tests_content = """
161+
import pytest
162+
163+
@pytest.mark.run(order=-1)
164+
class TestLast(object):
165+
166+
def test_1(self): pass
167+
168+
def test_2(self): pass
169+
170+
171+
@pytest.mark.run(order=0)
172+
def test_3(): pass
173+
174+
175+
@pytest.mark.run(order=-2)
176+
class TestFirst(object):
177+
178+
def test_4(self): pass
179+
180+
def test_5(self): pass
181+
"""
182+
183+
assert item_names_for(tests_content) == ['test_3', 'test_4', 'test_5', 'test_1', 'test_2']
184+
185+
186+
def test_run_marker_registered(capsys):
187+
pytest.main('--markers')
188+
out, err = capsys.readouterr()
189+
assert '@pytest.mark.run' in out
190+
191+
192+
def test_version_valid():
193+
assert re.match(r'[0-9]+\.[0-9]+(\.[0-9]+)?$',
194+
pytest_ordering.version.__version__)
195+
196+
197+
def test_author_present():
198+
assert hasattr(pytest_ordering.author, '__author__')

0 commit comments

Comments
 (0)