tests: cleanup unused fixtures

This commit is contained in:
Daniel Hahler 2020-01-16 19:42:29 +01:00
parent d36c712bb0
commit 5049e25a6a
17 changed files with 35 additions and 35 deletions

View File

@ -606,7 +606,7 @@ class TestInvocationVariants:
def test_equivalence_pytest_pytest(self): def test_equivalence_pytest_pytest(self):
assert pytest.main == py.test.cmdline.main assert pytest.main == py.test.cmdline.main
def test_invoke_with_invalid_type(self, capsys): def test_invoke_with_invalid_type(self):
with pytest.raises( with pytest.raises(
TypeError, match="expected to be a list or tuple of strings, got: '-h'" TypeError, match="expected to be a list or tuple of strings, got: '-h'"
): ):
@ -617,7 +617,7 @@ class TestInvocationVariants:
assert retcode == ExitCode.NO_TESTS_COLLECTED assert retcode == ExitCode.NO_TESTS_COLLECTED
out, err = capsys.readouterr() out, err = capsys.readouterr()
def test_invoke_plugin_api(self, testdir, capsys): def test_invoke_plugin_api(self, capsys):
class MyPlugin: class MyPlugin:
def pytest_addoption(self, parser): def pytest_addoption(self, parser):
parser.addoption("--myopt") parser.addoption("--myopt")

View File

@ -17,7 +17,7 @@ if sys.gettrace():
@pytest.hookimpl(hookwrapper=True, tryfirst=True) @pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_collection_modifyitems(config, items): def pytest_collection_modifyitems(items):
"""Prefer faster tests. """Prefer faster tests.
Use a hookwrapper to do this in the beginning, so e.g. --ff still works Use a hookwrapper to do this in the beginning, so e.g. --ff still works

View File

@ -626,7 +626,7 @@ def test_log_cli_ini_level(testdir):
"cli_args", "cli_args",
["", "--log-level=WARNING", "--log-file-level=WARNING", "--log-cli-level=WARNING"], ["", "--log-level=WARNING", "--log-file-level=WARNING", "--log-cli-level=WARNING"],
) )
def test_log_cli_auto_enable(testdir, request, cli_args): def test_log_cli_auto_enable(testdir, cli_args):
"""Check that live logs are enabled if --log-level or --log-cli-level is passed on the CLI. """Check that live logs are enabled if --log-level or --log-cli-level is passed on the CLI.
It should not be auto enabled if the same configs are set on the INI file. It should not be auto enabled if the same configs are set on the INI file.
""" """

View File

@ -286,7 +286,7 @@ class TestFunction:
return pytest.Function(config=config, parent=session, **kwargs) return pytest.Function(config=config, parent=session, **kwargs)
def test_function_equality(self, testdir, tmpdir): def test_function_equality(self, testdir):
def func1(): def func1():
pass pass
@ -492,7 +492,7 @@ class TestFunction:
) )
assert "foo" in keywords[1] and "bar" in keywords[1] and "baz" in keywords[1] assert "foo" in keywords[1] and "bar" in keywords[1] and "baz" in keywords[1]
def test_function_equality_with_callspec(self, testdir, tmpdir): def test_function_equality_with_callspec(self, testdir):
items = testdir.getitems( items = testdir.getitems(
""" """
import pytest import pytest
@ -509,11 +509,11 @@ class TestFunction:
config = item.config config = item.config
class MyPlugin1: class MyPlugin1:
def pytest_pyfunc_call(self, pyfuncitem): def pytest_pyfunc_call(self):
raise ValueError raise ValueError
class MyPlugin2: class MyPlugin2:
def pytest_pyfunc_call(self, pyfuncitem): def pytest_pyfunc_call(self):
return True return True
config.pluginmanager.register(MyPlugin1()) config.pluginmanager.register(MyPlugin1())
@ -1015,7 +1015,7 @@ class TestTracebackCutting:
class TestReportInfo: class TestReportInfo:
def test_itemreport_reportinfo(self, testdir, linecomp): def test_itemreport_reportinfo(self, testdir):
testdir.makeconftest( testdir.makeconftest(
""" """
import pytest import pytest

View File

@ -4238,7 +4238,7 @@ def test_fixture_named_request(testdir):
) )
def test_fixture_duplicated_arguments(testdir): def test_fixture_duplicated_arguments():
"""Raise error if there are positional and keyword arguments for the same parameter (#1682).""" """Raise error if there are positional and keyword arguments for the same parameter (#1682)."""
with pytest.raises(TypeError) as excinfo: with pytest.raises(TypeError) as excinfo:
@ -4253,7 +4253,7 @@ def test_fixture_duplicated_arguments(testdir):
) )
def test_fixture_with_positionals(testdir): def test_fixture_with_positionals():
"""Raise warning, but the positionals should still works (#1682).""" """Raise warning, but the positionals should still works (#1682)."""
from _pytest.deprecated import FIXTURE_POSITIONAL_ARGUMENTS from _pytest.deprecated import FIXTURE_POSITIONAL_ARGUMENTS

View File

@ -31,7 +31,7 @@ class TestMetafunc:
definition = DefinitionMock(func) definition = DefinitionMock(func)
return python.Metafunc(definition, fixtureinfo, config) return python.Metafunc(definition, fixtureinfo, config)
def test_no_funcargs(self, testdir): def test_no_funcargs(self):
def function(): def function():
pass pass
@ -61,7 +61,7 @@ class TestMetafunc:
pytest.raises(ValueError, lambda: metafunc.parametrize("y", [5, 6])) pytest.raises(ValueError, lambda: metafunc.parametrize("y", [5, 6]))
pytest.raises(ValueError, lambda: metafunc.parametrize("y", [5, 6])) pytest.raises(ValueError, lambda: metafunc.parametrize("y", [5, 6]))
def test_parametrize_bad_scope(self, testdir): def test_parametrize_bad_scope(self):
def func(x): def func(x):
pass pass
@ -153,7 +153,7 @@ class TestMetafunc:
ids = [x.id for x in metafunc._calls] ids = [x.id for x in metafunc._calls]
assert ids == ["basic", "advanced"] assert ids == ["basic", "advanced"]
def test_parametrize_with_wrong_number_of_ids(self, testdir): def test_parametrize_with_wrong_number_of_ids(self):
def func(x, y): def func(x, y):
pass pass
@ -652,7 +652,7 @@ class TestMetafunc:
result = testdir.runpytest("-v") result = testdir.runpytest("-v")
result.stdout.fnmatch_lines(["*test_simple*a-b*", "*1 passed*"]) result.stdout.fnmatch_lines(["*test_simple*a-b*", "*1 passed*"])
def test_parametrize_indirect_list_error(self, testdir): def test_parametrize_indirect_list_error(self):
"""#714""" """#714"""
def func(x, y): def func(x, y):

View File

@ -1299,7 +1299,7 @@ def test_AssertionError_message(testdir):
) )
def test_diff_newline_at_end(monkeypatch, testdir): def test_diff_newline_at_end(testdir):
testdir.makepyfile( testdir.makepyfile(
r""" r"""
def test_diff(): def test_diff():
@ -1354,7 +1354,7 @@ def test_assert_indirect_tuple_no_warning(testdir):
assert "WR1" not in output assert "WR1" not in output
def test_assert_with_unicode(monkeypatch, testdir): def test_assert_with_unicode(testdir):
testdir.makepyfile( testdir.makepyfile(
"""\ """\
def test_unicode(): def test_unicode():

View File

@ -937,7 +937,7 @@ class TestFDCapture:
cap.done() cap.done()
assert s == "hello\n" assert s == "hello\n"
def test_stdin(self, tmpfile): def test_stdin(self):
cap = capture.FDCapture(0) cap = capture.FDCapture(0)
cap.start() cap.start()
x = os.read(0, 100).strip() x = os.read(0, 100).strip()
@ -958,7 +958,7 @@ class TestFDCapture:
stmp = stmp_file.read() stmp = stmp_file.read()
assert stmp == data2 assert stmp == data2
def test_simple_resume_suspend(self, tmpfile): def test_simple_resume_suspend(self):
with saved_fd(1): with saved_fd(1):
cap = capture.FDCapture(1) cap = capture.FDCapture(1)
cap.start() cap.start()

View File

@ -243,7 +243,7 @@ class TestCollectPluginHookRelay:
wascalled = [] wascalled = []
class Plugin: class Plugin:
def pytest_collect_file(self, path, parent): def pytest_collect_file(self, path):
if not path.basename.startswith("."): if not path.basename.startswith("."):
# Ignore hidden files, e.g. .testmondata. # Ignore hidden files, e.g. .testmondata.
wascalled.append(path) wascalled.append(path)
@ -257,7 +257,7 @@ class TestCollectPluginHookRelay:
wascalled = [] wascalled = []
class Plugin: class Plugin:
def pytest_collect_directory(self, path, parent): def pytest_collect_directory(self, path):
wascalled.append(path.basename) wascalled.append(path.basename)
testdir.mkdir("hello") testdir.mkdir("hello")
@ -1173,7 +1173,7 @@ def test_collect_symlink_out_of_tree(testdir):
assert result.ret == 0 assert result.ret == 0
def test_collectignore_via_conftest(testdir, monkeypatch): def test_collectignore_via_conftest(testdir):
"""collect_ignore in parent conftest skips importing child (issue #4592).""" """collect_ignore in parent conftest skips importing child (issue #4592)."""
tests = testdir.mkpydir("tests") tests = testdir.mkpydir("tests")
tests.ensure("conftest.py").write("collect_ignore = ['ignore_me']") tests.ensure("conftest.py").write("collect_ignore = ['ignore_me']")

View File

@ -357,7 +357,7 @@ def test_conftest_import_order(testdir, monkeypatch):
assert conftest._getconftestmodules(sub) == [ct1, ct2] assert conftest._getconftestmodules(sub) == [ct1, ct2]
def test_fixture_dependency(testdir, monkeypatch): def test_fixture_dependency(testdir):
ct1 = testdir.makeconftest("") ct1 = testdir.makeconftest("")
ct1 = testdir.makepyfile("__init__.py") ct1 = testdir.makepyfile("__init__.py")
ct1.write("") ct1.write("")

View File

@ -82,7 +82,7 @@ def test_timeout(testdir, enabled):
@pytest.mark.parametrize("hook_name", ["pytest_enter_pdb", "pytest_exception_interact"]) @pytest.mark.parametrize("hook_name", ["pytest_enter_pdb", "pytest_exception_interact"])
def test_cancel_timeout_on_hook(monkeypatch, pytestconfig, hook_name): def test_cancel_timeout_on_hook(monkeypatch, hook_name):
"""Make sure that we are cancelling any scheduled traceback dumping due """Make sure that we are cancelling any scheduled traceback dumping due
to timeout before entering pdb (pytest-dev/pytest-faulthandler#12) or any other interactive to timeout before entering pdb (pytest-dev/pytest-faulthandler#12) or any other interactive
exception (pytest-dev/pytest-faulthandler#14). exception (pytest-dev/pytest-faulthandler#14).

View File

@ -57,7 +57,7 @@ def test_traceconfig(testdir):
result.stdout.fnmatch_lines(["*using*pytest*py*", "*active plugins*"]) result.stdout.fnmatch_lines(["*using*pytest*py*", "*active plugins*"])
def test_debug(testdir, monkeypatch): def test_debug(testdir):
result = testdir.runpytest_subprocess("--debug") result = testdir.runpytest_subprocess("--debug")
assert result.ret == ExitCode.NO_TESTS_COLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
p = testdir.tmpdir.join("pytestdebug.log") p = testdir.tmpdir.join("pytestdebug.log")

View File

@ -41,7 +41,7 @@ class TestMark:
mark._some_name mark._some_name
def test_marked_class_run_twice(testdir, request): def test_marked_class_run_twice(testdir):
"""Test fails file is run twice that contains marked class. """Test fails file is run twice that contains marked class.
See issue#683. See issue#683.
""" """

View File

@ -254,14 +254,14 @@ class TestParser:
assert args.func_arg is False assert args.func_arg is False
assert args.file_or_dir == ["abcd"] assert args.file_or_dir == ["abcd"]
def test_drop_short_help0(self, parser, capsys): def test_drop_short_help0(self, parser):
parser.addoption("--func-args", "--doit", help="foo", action="store_true") parser.addoption("--func-args", "--doit", help="foo", action="store_true")
parser.parse([]) parser.parse([])
help = parser.optparser.format_help() help = parser.optparser.format_help()
assert "--func-args, --doit foo" in help assert "--func-args, --doit foo" in help
# testing would be more helpful with all help generated # testing would be more helpful with all help generated
def test_drop_short_help1(self, parser, capsys): def test_drop_short_help1(self, parser):
group = parser.getgroup("general") group = parser.getgroup("general")
group.addoption("--doit", "--func-args", action="store_true", help="foo") group.addoption("--doit", "--func-args", action="store_true", help="foo")
group._addoption( group._addoption(

View File

@ -463,7 +463,7 @@ class TestPDB:
child.read() child.read()
self.flush(child) self.flush(child)
def test_pdb_interaction_doctest(self, testdir, monkeypatch): def test_pdb_interaction_doctest(self, testdir):
p1 = testdir.makepyfile( p1 = testdir.makepyfile(
""" """
def function_1(): def function_1():
@ -489,7 +489,7 @@ class TestPDB:
assert "1 failed" in rest assert "1 failed" in rest
self.flush(child) self.flush(child)
def test_doctest_set_trace_quit(self, testdir, monkeypatch): def test_doctest_set_trace_quit(self, testdir):
p1 = testdir.makepyfile( p1 = testdir.makepyfile(
""" """
def function_1(): def function_1():
@ -833,7 +833,7 @@ class TestPDB:
] ]
) )
def test_pdb_validate_usepdb_cls(self, testdir): def test_pdb_validate_usepdb_cls(self):
assert _validate_usepdb_cls("os.path:dirname.__name__") == ( assert _validate_usepdb_cls("os.path:dirname.__name__") == (
"os.path", "os.path",
"dirname.__name__", "dirname.__name__",

View File

@ -71,7 +71,7 @@ class TestPytestPluginInteractions:
values = [] values = []
class A: class A:
def pytest_configure(self, config): def pytest_configure(self):
values.append(self) values.append(self)
config.pluginmanager.register(A()) config.pluginmanager.register(A())

View File

@ -621,7 +621,7 @@ class TestTerminalFunctional:
if request.config.pluginmanager.list_plugin_distinfo(): if request.config.pluginmanager.list_plugin_distinfo():
result.stdout.fnmatch_lines(["plugins: *"]) result.stdout.fnmatch_lines(["plugins: *"])
def test_header(self, testdir, request): def test_header(self, testdir):
testdir.tmpdir.join("tests").ensure_dir() testdir.tmpdir.join("tests").ensure_dir()
testdir.tmpdir.join("gui").ensure_dir() testdir.tmpdir.join("gui").ensure_dir()
@ -687,7 +687,7 @@ class TestTerminalFunctional:
""" """
) )
def test_verbose_reporting(self, verbose_testfile, testdir, pytestconfig): def test_verbose_reporting(self, verbose_testfile, testdir):
result = testdir.runpytest( result = testdir.runpytest(
verbose_testfile, "-v", "-Walways::pytest.PytestWarning" verbose_testfile, "-v", "-Walways::pytest.PytestWarning"
) )
@ -943,7 +943,7 @@ def test_tbstyle_short(testdir):
assert "assert x" in s assert "assert x" in s
def test_traceconfig(testdir, monkeypatch): def test_traceconfig(testdir):
result = testdir.runpytest("--traceconfig") result = testdir.runpytest("--traceconfig")
result.stdout.fnmatch_lines(["*active plugins*"]) result.stdout.fnmatch_lines(["*active plugins*"])
assert result.ret == ExitCode.NO_TESTS_COLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED