Skip to content

Commit 118cb3d

Browse files
committed
Fix test_config: wrong assertions, lint, unused fixtures
1 parent b91c721 commit 118cb3d

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

testing/test_config.py

+19-25
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_getcfg_and_config(self, testdir, tmpdir, section, filename):
3232
)
3333
)
3434
)
35-
rootdir, inifile, cfg = getcfg([sub])
35+
_, _, cfg = getcfg([sub])
3636
assert cfg["name"] == "value"
3737
config = testdir.parseconfigure(sub)
3838
assert config.inicfg["name"] == "value"
@@ -441,8 +441,6 @@ def test_iter_rewritable_modules(self, names, expected):
441441

442442
class TestConfigFromdictargs:
443443
def test_basic_behavior(self, _sys_snapshot):
444-
from _pytest.config import Config
445-
446444
option_dict = {"verbose": 444, "foo": "bar", "capture": "no"}
447445
args = ["a", "b"]
448446

@@ -456,8 +454,6 @@ def test_basic_behavior(self, _sys_snapshot):
456454

457455
def test_invocation_params_args(self, _sys_snapshot):
458456
"""Show that fromdictargs can handle args in their "orig" format"""
459-
from _pytest.config import Config
460-
461457
option_dict = {}
462458
args = ["-vvvv", "-s", "a", "b"]
463459

@@ -477,8 +473,6 @@ def test_inifilename(self, tmpdir):
477473
)
478474
)
479475

480-
from _pytest.config import Config
481-
482476
inifile = "../../foo/bar.ini"
483477
option_dict = {"inifilename": inifile, "capture": "no"}
484478

@@ -771,23 +765,23 @@ def test_notify_exception(testdir, capfd):
771765
with pytest.raises(ValueError) as excinfo:
772766
raise ValueError(1)
773767
config.notify_exception(excinfo, config.option)
774-
out, err = capfd.readouterr()
768+
_, err = capfd.readouterr()
775769
assert "ValueError" in err
776770

777771
class A:
778-
def pytest_internalerror(self, excrepr):
772+
def pytest_internalerror(self):
779773
return True
780774

781775
config.pluginmanager.register(A())
782776
config.notify_exception(excinfo, config.option)
783-
out, err = capfd.readouterr()
777+
_, err = capfd.readouterr()
784778
assert not err
785779

786780
config = testdir.parseconfig("-p", "no:terminal")
787781
with pytest.raises(ValueError) as excinfo:
788782
raise ValueError(1)
789783
config.notify_exception(excinfo, config.option)
790-
out, err = capfd.readouterr()
784+
_, err = capfd.readouterr()
791785
assert "ValueError" in err
792786

793787

@@ -797,7 +791,7 @@ def test_no_terminal_discovery_error(testdir):
797791
assert result.ret == ExitCode.INTERRUPTED
798792

799793

800-
def test_load_initial_conftest_last_ordering(testdir, _config_for_test):
794+
def test_load_initial_conftest_last_ordering(_config_for_test):
801795
pm = _config_for_test.pluginmanager
802796

803797
class My:
@@ -866,21 +860,21 @@ def test_with_ini(self, tmpdir, name) -> None:
866860
a = tmpdir.mkdir("a")
867861
b = a.mkdir("b")
868862
for args in ([tmpdir], [a], [b]):
869-
rootdir, inifile, inicfg = determine_setup(None, args)
863+
rootdir, parsed_inifile, _ = determine_setup(None, args)
870864
assert rootdir == tmpdir
871-
assert inifile == inifile
872-
rootdir, inifile, inicfg = determine_setup(None, [b, a])
865+
assert parsed_inifile == inifile
866+
rootdir, parsed_inifile, _ = determine_setup(None, [b, a])
873867
assert rootdir == tmpdir
874-
assert inifile == inifile
868+
assert parsed_inifile == inifile
875869

876870
@pytest.mark.parametrize("name", "setup.cfg tox.ini".split())
877871
def test_pytestini_overrides_empty_other(self, tmpdir, name) -> None:
878872
inifile = tmpdir.ensure("pytest.ini")
879873
a = tmpdir.mkdir("a")
880874
a.ensure(name)
881-
rootdir, inifile, inicfg = determine_setup(None, [a])
875+
rootdir, parsed_inifile, _ = determine_setup(None, [a])
882876
assert rootdir == tmpdir
883-
assert inifile == inifile
877+
assert parsed_inifile == inifile
884878

885879
def test_setuppy_fallback(self, tmpdir) -> None:
886880
a = tmpdir.mkdir("a")
@@ -900,7 +894,7 @@ def test_nothing(self, tmpdir, monkeypatch) -> None:
900894

901895
def test_with_specific_inifile(self, tmpdir) -> None:
902896
inifile = tmpdir.ensure("pytest.ini")
903-
rootdir, inifile, inicfg = determine_setup(inifile, [tmpdir])
897+
rootdir, _, _ = determine_setup(inifile, [tmpdir])
904898
assert rootdir == tmpdir
905899

906900

@@ -1043,30 +1037,30 @@ def test_with_arg_outside_cwd_without_inifile(self, tmpdir, monkeypatch) -> None
10431037
monkeypatch.chdir(str(tmpdir))
10441038
a = tmpdir.mkdir("a")
10451039
b = tmpdir.mkdir("b")
1046-
rootdir, inifile, inicfg = determine_setup(None, [a, b])
1040+
rootdir, inifile, _ = determine_setup(None, [a, b])
10471041
assert rootdir == tmpdir
10481042
assert inifile is None
10491043

10501044
def test_with_arg_outside_cwd_with_inifile(self, tmpdir) -> None:
10511045
a = tmpdir.mkdir("a")
10521046
b = tmpdir.mkdir("b")
10531047
inifile = a.ensure("pytest.ini")
1054-
rootdir, parsed_inifile, inicfg = determine_setup(None, [a, b])
1048+
rootdir, parsed_inifile, _ = determine_setup(None, [a, b])
10551049
assert rootdir == a
10561050
assert inifile == parsed_inifile
10571051

10581052
@pytest.mark.parametrize("dirs", ([], ["does-not-exist"], ["a/does-not-exist"]))
10591053
def test_with_non_dir_arg(self, dirs, tmpdir) -> None:
10601054
with tmpdir.ensure(dir=True).as_cwd():
1061-
rootdir, inifile, inicfg = determine_setup(None, dirs)
1055+
rootdir, inifile, _ = determine_setup(None, dirs)
10621056
assert rootdir == tmpdir
10631057
assert inifile is None
10641058

10651059
def test_with_existing_file_in_subdir(self, tmpdir) -> None:
10661060
a = tmpdir.mkdir("a")
10671061
a.ensure("exist")
10681062
with tmpdir.as_cwd():
1069-
rootdir, inifile, inicfg = determine_setup(None, ["a/exist"])
1063+
rootdir, inifile, _ = determine_setup(None, ["a/exist"])
10701064
assert rootdir == tmpdir
10711065
assert inifile is None
10721066

@@ -1111,7 +1105,7 @@ def test_override_ini_does_not_contain_paths(self, _config_for_test, _sys_snapsh
11111105
config._preparse(["-o", "cache_dir=/cache", "/some/test/path"])
11121106
assert config._override_ini == ["cache_dir=/cache"]
11131107

1114-
def test_multiple_override_ini_options(self, testdir, request):
1108+
def test_multiple_override_ini_options(self, testdir):
11151109
"""Ensure a file path following a '-o' option does not generate an error (#3103)"""
11161110
testdir.makepyfile(
11171111
**{
@@ -1201,7 +1195,7 @@ def pytest_addoption(parser):
12011195
assert result.ret == ExitCode.USAGE_ERROR
12021196

12031197

1204-
def test_help_formatter_uses_py_get_terminal_width(testdir, monkeypatch):
1198+
def test_help_formatter_uses_py_get_terminal_width(monkeypatch):
12051199
from _pytest.config.argparsing import DropShorterLongHelpFormatter
12061200

12071201
monkeypatch.setenv("COLUMNS", "90")

0 commit comments

Comments
 (0)