11"""Tests."""
22
3+ import logging
34import os
45
56import pytest
67
78pytest_plugins = ["pytester" ]
89
910
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 :
1116 """Validates that we can detect duplicate test names."""
17+ monkeypatch .delenv ("PYTEST_REQPASS" , raising = False )
18+ caplog .set_level (logging .INFO )
1219 p1 = pytester .makepyfile (
1320 test_one = """
1421 def test_a():
@@ -24,25 +31,28 @@ def test_a():
2431
2532 result = pytester .runpytest_inprocess (p1 , p2 )
2633 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
2936 )
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
3538
3639
3740@pytest .mark .parametrize (
3841 ("rc" , "disable" ),
3942 [
40- pytest .param (pytest .ExitCode .USAGE_ERROR , False , id = "0" ),
43+ pytest .param (pytest .ExitCode .OK , False , id = "0" ),
4144 pytest .param (pytest .ExitCode .OK , True , id = "1" ),
4245 ],
4346)
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 :
4554 """Validates that we can detect duplicate test names."""
55+ caplog .set_level (logging .WARNING )
4656 if disable :
4757 os .environ ["PYTEST_CHECK_TEST_ID_REGEX" ] = "0"
4858 p1 = pytester .makepyfile (
@@ -62,13 +72,17 @@ def test_a(some: str):
6272 if not disable :
6373 assert (
6474 "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
6676 )
6777 assert result .ret == rc
6878
6979
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 :
7184 """Validates that we can detect duplicate test names."""
85+ caplog .set_level (logging .WARNING )
7286 p1 = pytester .makepyfile (
7387 test_one = """
7488 import pytest
@@ -85,6 +99,6 @@ def test_a(some: str):
8599 result = pytester .runpytest_inprocess ("--collect-only" , p1 )
86100 assert (
87101 "<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
89103 )
90- assert result .ret == pytest .ExitCode .USAGE_ERROR
104+ assert result .ret == pytest .ExitCode .OK
0 commit comments