Skip to content

Commit

Permalink
Avoid deprecated pytest.warns(None) (#2548)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hroncok committed Nov 26, 2022
1 parent 0e1054b commit 3b83cd4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tests/unit/config/test_config.py
Expand Up @@ -2,6 +2,7 @@
import os
import re
import sys
import warnings
from textwrap import dedent

import py
Expand Down Expand Up @@ -2469,7 +2470,8 @@ def get_executable(self, envconfig):

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

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

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

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

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

def test_default_factors_conflict_ignore(self, newconfig, capsys):
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error")
config = newconfig(
"""
[tox]
Expand All @@ -2516,7 +2518,6 @@ def test_default_factors_conflict_ignore(self, newconfig, capsys):
assert len(config.envconfigs) == 1
envconfig = config.envconfigs["py27"]
assert envconfig.basepython == "python2.7"
assert len(record) == 0, "\n".join(repr(r.message) for r in record)

def test_factors_in_boolean(self, newconfig):
inisource = """
Expand Down

0 comments on commit 3b83cd4

Please sign in to comment.