Skip to content

Commit 4a916ae

Browse files
committed
Simplify all tests and make them a lot cleaner
This also completely removes the necessity to use the py.code module and the internal test.util module.
1 parent 68a478c commit 4a916ae

File tree

13 files changed

+221
-227
lines changed

13 files changed

+221
-227
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ on:
1313

1414
jobs:
1515
build:
16-
runs-on: ubuntu-22.04
16+
runs-on: ubuntu-latest
1717

1818
strategy:
1919
matrix:
20-
python: ['3.7', '3.8', '3.9', '3.10', 'py3.11', 'pypy3.9']
20+
python: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy3.9']
2121

2222
steps:
2323
- uses: actions/checkout@v3
@@ -36,31 +36,31 @@ jobs:
3636
3737
- name: Test with Python 3.7
3838
if: matrix.python == '3.7'
39-
run: tox -e 'py37-pytest{4,5,60,61,62,70,71,72,73}'
39+
run: tox run -x "tox.envlist=py37-pytest{4,5,60,61,62,70,71,72,73}"
4040

4141
- name: Test with Python 3.8
4242
if: matrix.python == '3.8'
43-
run: tox -e 'py38-pytest{4,5,60,61,62,70,71,72,73}'
43+
run: tox run -x "tox.envlist=py38-pytest{4,5,60,61,62,70,71,72,73}"
4444

4545
- name: Test with Python 3.9
4646
if: matrix.python == '3.9'
47-
run: tox -e 'py39-pytest{4,5,60,61,62,70,71,72,73}'
47+
run: tox run -x "tox.envlist=py39-pytest{4,5,60,61,62,70,71,72,73}"
4848

4949
- name: Test with Python 3.10
5050
if: matrix.python == '3.10'
51-
run: tox -e 'py310-pytest{62,70,71,72,73}'
51+
run: tox run -x "tox.envlist=py310-pytest{62,70,71,72,73}"
5252

5353
- name: Test with Python 3.11
5454
if: matrix.python == '3.11'
55-
run: tox -e 'py311-pytest{73}'
55+
run: tox run -x "tox.envlist=spy311-pytest{73}"
5656

5757
- name: Test with PyPy 3.9
5858
if: matrix.python == 'pypy3.9'
59-
run: tox -e 'pypy39-pytest{4,5,60,61,62,70,71,72,73}'
59+
run: tox run -x "tox.envlist=pypy39-pytest{4,5,60,61,62,70,71,72,73}"
6060

6161
- name: Linting with Flake8
6262
if: matrix.python == '3.10'
63-
run: tox -e flake8
63+
run: tox run -e flake8
6464

6565
deploy:
6666
if: |

pytest_describe/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
from .shared import behaves_like
22

33

4-
__all__ = [
5-
behaves_like,
6-
]
4+
__all__ = ["behaves_like"]

test/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Global fixtures for testing the plugin"""
2+
3+
pytest_plugins = ["pytester"]

test/test_collect.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import re
1+
"""Test collection of test functions"""
22

3-
from util import assert_outcomes, Source
43

5-
pytest_plugins = 'pytester'
6-
7-
8-
def test_collect(testdir):
9-
a_dir = testdir.mkpydir('a_dir')
10-
a_dir.join('test_a.py').write(Source("""
4+
def test_collect_only(testdir):
5+
testdir.makepyfile(
6+
"""
117
def describe_something():
128
def is_foo():
139
pass
@@ -23,27 +19,28 @@ def foo_not_collected():
2319
pass
2420
def test_something():
2521
pass
26-
"""))
22+
""")
2723

2824
result = testdir.runpytest('--collectonly')
29-
30-
expected_regex = map(re.compile, [
31-
r"collected 4 item(s)?",
32-
r"\s*<DescribeBlock '?describe_something'?>",
33-
r"\s*<Function '?is_foo'?>",
34-
r"\s*<Function '?can_bar'?>",
35-
r"\s*<DescribeBlock '?describe_something_else'?>",
36-
r"\s*<DescribeBlock '?describe_nested'?>",
37-
r"\s*<Function '?a_test'?>",
38-
r"\s*<Function '?test_something'?>",
39-
])
40-
for line in expected_regex:
41-
assert any([line.match(r) is not None for r in result.outlines])
25+
result.assert_outcomes()
26+
27+
output = '\n'.join(filter(None, result.outlines))
28+
assert """
29+
collected 4 items
30+
<Module test_collect_only.py>
31+
<DescribeBlock 'describe_something'>
32+
<Function is_foo>
33+
<Function can_bar>
34+
<DescribeBlock 'describe_something_else'>
35+
<DescribeBlock 'describe_nested'>
36+
<Function a_test>
37+
<Function test_something>
38+
""" in output
4239

4340

4441
def test_describe_evaluated_once(testdir):
45-
a_dir = testdir.mkpydir('a_dir')
46-
a_dir.join('test_something.py').write(Source("""
42+
testdir.makepyfile(
43+
"""
4744
count = 0
4845
def describe_is_evaluated_only_once():
4946
global count
@@ -55,7 +52,7 @@ def two():
5552
def describe_nested():
5653
def three():
5754
assert count == 1
58-
"""))
55+
""")
5956

6057
result = testdir.runpytest('-v')
61-
assert_outcomes(result, passed=3)
58+
result.assert_outcomes(passed=3)

test/test_custom_prefix.py

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

test/test_fixtures.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
from util import assert_outcomes, Source
2-
3-
pytest_plugins = 'pytester'
1+
"""Test with fixtures"""
42

53

64
def test_can_access_local_fixture(testdir):
7-
a_dir = testdir.mkpydir('a_dir')
8-
a_dir.join('test_a.py').write(Source("""
5+
testdir.makepyfile(
6+
"""
97
import pytest
108
119
def describe_something():
@@ -15,15 +13,15 @@ def thing():
1513
1614
def thing_is_42(thing):
1715
assert thing == 42
18-
"""))
16+
""")
1917

2018
result = testdir.runpytest()
21-
assert_outcomes(result, passed=1)
19+
result.assert_outcomes(passed=1)
2220

2321

2422
def test_can_access_fixture_from_nested_scope(testdir):
25-
a_dir = testdir.mkpydir('a_dir')
26-
a_dir.join('test_a.py').write(Source("""
23+
testdir.makepyfile(
24+
"""
2725
import pytest
2826
2927
def describe_something():
@@ -34,15 +32,15 @@ def thing():
3432
def describe_a_nested_scope():
3533
def thing_is_42(thing):
3634
assert thing == 42
37-
"""))
35+
""")
3836

3937
result = testdir.runpytest()
40-
assert_outcomes(result, passed=1)
38+
result.assert_outcomes(passed=1)
4139

4240

4341
def test_local_fixture_overrides(testdir):
44-
a_dir = testdir.mkpydir('a_dir')
45-
a_dir.join('test_a.py').write(Source("""
42+
testdir.makepyfile(
43+
"""
4644
import pytest
4745
4846
@pytest.fixture
@@ -60,7 +58,7 @@ def thing_is_42(thing):
6058
6159
def thing_is_12(thing):
6260
assert thing == 12
63-
"""))
61+
""")
6462

6563
result = testdir.runpytest()
66-
assert_outcomes(result, passed=2)
64+
result.assert_outcomes(passed=2)

0 commit comments

Comments
 (0)