1
1
"""Tests."""
2
2
3
+ import logging
3
4
import os
4
5
5
6
import pytest
6
7
7
8
pytest_plugins = ["pytester" ]
8
9
9
10
10
- def test_duplicate_test_name (pytester : pytest .Pytester ) -> None :
11
+ def test_duplicate_test_name (
12
+ pytester : pytest .Pytester ,
13
+ caplog : pytest .LogCaptureFixture ,
14
+ monkeypatch : pytest .MonkeyPatch ,
15
+ ) -> None :
11
16
"""Validates that we can detect duplicate test names."""
17
+ monkeypatch .delenv ("PYTEST_REQPASS" , raising = False )
18
+ caplog .set_level (logging .INFO )
12
19
p1 = pytester .makepyfile (
13
20
test_one = """
14
21
def test_a():
@@ -24,25 +31,28 @@ def test_a():
24
31
25
32
result = pytester .runpytest_inprocess (p1 , p2 )
26
33
assert (
27
- result . errlines [ 0 ]
28
- == "ERROR: Failed run due to following issues being identified:"
34
+ "Duplicate test name 'test_a', found at test_two.py:0 and test_one.py:0"
35
+ in caplog . text
29
36
)
30
- assert (
31
- result .errlines [1 ]
32
- == "Duplicate test name 'test_a', found at test_two.py:0 and test_one.py:0"
33
- )
34
- assert result .ret == pytest .ExitCode .USAGE_ERROR
37
+ assert result .ret == 0 , result .stdout .lines
35
38
36
39
37
40
@pytest .mark .parametrize (
38
41
("rc" , "disable" ),
39
42
[
40
- pytest .param (pytest .ExitCode .USAGE_ERROR , False , id = "0" ),
43
+ pytest .param (pytest .ExitCode .OK , False , id = "0" ),
41
44
pytest .param (pytest .ExitCode .OK , True , id = "1" ),
42
45
],
43
46
)
44
- def test_check_test_id (pytester : pytest .Pytester , rc : int , * , disable : bool ) -> None :
47
+ def test_check_test_id (
48
+ pytester : pytest .Pytester ,
49
+ rc : int ,
50
+ * ,
51
+ disable : bool ,
52
+ caplog : pytest .LogCaptureFixture ,
53
+ ) -> None :
45
54
"""Validates that we can detect duplicate test names."""
55
+ caplog .set_level (logging .WARNING )
46
56
if disable :
47
57
os .environ ["PYTEST_CHECK_TEST_ID_REGEX" ] = "0"
48
58
p1 = pytester .makepyfile (
@@ -62,13 +72,17 @@ def test_a(some: str):
62
72
if not disable :
63
73
assert (
64
74
"Test <Function test_a[invalid name]> has an id that does not match our safe pattern '^[\\ w_\\ -\\ .:]+$' for use with a terminal."
65
- in result . stderr . lines
75
+ in caplog . text
66
76
)
67
77
assert result .ret == rc
68
78
69
79
70
- def test_check_test_id_length (pytester : pytest .Pytester ) -> None :
80
+ def test_check_test_id_length (
81
+ pytester : pytest .Pytester ,
82
+ caplog : pytest .LogCaptureFixture ,
83
+ ) -> None :
71
84
"""Validates that we can detect duplicate test names."""
85
+ caplog .set_level (logging .WARNING )
72
86
p1 = pytester .makepyfile (
73
87
test_one = """
74
88
import pytest
@@ -85,6 +99,6 @@ def test_a(some: str):
85
99
result = pytester .runpytest_inprocess ("--collect-only" , p1 )
86
100
assert (
87
101
"<Function test_a[this-is-too-long-for-our-taste-so-we-ask-you-to-make-it-shorter]> has an id that looks above 60 characters."
88
- in result . stderr . lines
102
+ in caplog . text
89
103
)
90
- assert result .ret == pytest .ExitCode .USAGE_ERROR
104
+ assert result .ret == pytest .ExitCode .OK
0 commit comments