Skip to content

Commit 3b83cd4

Browse files
authored
Avoid deprecated pytest.warns(None) (#2548)
tests/unit/config/test_config.py::TestConfigTestEnv::test_default_single_digit_factors tests/unit/config/test_config.py::TestConfigTestEnv::test_default_single_digit_factors tests/unit/config/test_config.py::TestConfigTestEnv::test_default_factors_conflict_ignore /usr/lib/python3.11/site-packages/_pytest/python.py:192: PytestRemovedIn8Warning: Passing None has been deprecated. See https://docs.pytest.org/en/latest/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests for alternatives in common use cases.
1 parent 0e1054b commit 3b83cd4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tests/unit/config/test_config.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import re
44
import sys
5+
import warnings
56
from textwrap import dedent
67

78
import py
@@ -2469,7 +2470,8 @@ def get_executable(self, envconfig):
24692470

24702471
major, minor = sys.version_info[0:2]
24712472

2472-
with pytest.warns(None) as lying:
2473+
with warnings.catch_warnings():
2474+
warnings.simplefilter("error")
24732475
config = newconfig(
24742476
"""
24752477
[testenv:py{0}]
@@ -2483,9 +2485,9 @@ def get_executable(self, envconfig):
24832485

24842486
env_config = config.envconfigs["py{}".format(major)]
24852487
assert env_config.basepython == "python{}.{}".format(major, minor - 1)
2486-
assert len(lying) == 0, "\n".join(repr(r.message) for r in lying)
24872488

2488-
with pytest.warns(None) as truthful:
2489+
with warnings.catch_warnings():
2490+
warnings.simplefilter("error")
24892491
config = newconfig(
24902492
"""
24912493
[testenv:py{0}]
@@ -2499,10 +2501,10 @@ def get_executable(self, envconfig):
24992501

25002502
env_config = config.envconfigs["py{}".format(major)]
25012503
assert env_config.basepython == "python{}.{}".format(major, minor)
2502-
assert len(truthful) == 0, "\n".join(repr(r.message) for r in truthful)
25032504

25042505
def test_default_factors_conflict_ignore(self, newconfig, capsys):
2505-
with pytest.warns(None) as record:
2506+
with warnings.catch_warnings():
2507+
warnings.simplefilter("error")
25062508
config = newconfig(
25072509
"""
25082510
[tox]
@@ -2516,7 +2518,6 @@ def test_default_factors_conflict_ignore(self, newconfig, capsys):
25162518
assert len(config.envconfigs) == 1
25172519
envconfig = config.envconfigs["py27"]
25182520
assert envconfig.basepython == "python2.7"
2519-
assert len(record) == 0, "\n".join(repr(r.message) for r in record)
25202521

25212522
def test_factors_in_boolean(self, newconfig):
25222523
inisource = """

0 commit comments

Comments
 (0)