From a2f021b6f3618f30d0cd5604797ce5069353d864 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 10 Jul 2020 09:44:14 +0300 Subject: [PATCH] Remove no longer needed `noqa: F821` uses Not needed since pyflakes 2.2.0. --- src/_pytest/_io/saferepr.py | 4 ++-- src/_pytest/debugging.py | 4 ++-- src/_pytest/doctest.py | 10 ++++----- src/_pytest/fixtures.py | 22 +++++++++---------- src/_pytest/junitxml.py | 2 +- src/_pytest/logging.py | 4 ++-- src/_pytest/mark/structures.py | 4 ++-- src/_pytest/nodes.py | 4 ++-- src/_pytest/python.py | 6 ++--- src/_pytest/recwarn.py | 2 +- src/_pytest/runner.py | 12 +++++----- src/_pytest/setuponly.py | 4 ++-- src/_pytest/skipping.py | 2 +- src/_pytest/terminal.py | 2 +- src/_pytest/unittest.py | 12 +++++----- testing/code/test_excinfo.py | 2 +- .../test_compare_two_different_dataclasses.py | 2 +- testing/io/test_saferepr.py | 8 +++---- testing/python/collect.py | 6 ++--- testing/python/fixtures.py | 10 ++++----- testing/python/metafunc.py | 10 ++++----- testing/python/raises.py | 12 +++++----- testing/test_assertrewrite.py | 10 ++++----- testing/test_capture.py | 2 +- testing/test_collection.py | 6 ++--- testing/test_config.py | 2 +- testing/test_doctest.py | 2 +- testing/test_junitxml.py | 2 +- testing/test_mark.py | 8 +++---- testing/test_nodes.py | 4 ++-- testing/test_pytester.py | 14 ++++++------ testing/test_runner.py | 4 ++-- testing/test_store.py | 2 +- testing/test_terminal.py | 2 +- 34 files changed, 101 insertions(+), 101 deletions(-) diff --git a/src/_pytest/_io/saferepr.py b/src/_pytest/_io/saferepr.py index 6b9f353a2..823b8d719 100644 --- a/src/_pytest/_io/saferepr.py +++ b/src/_pytest/_io/saferepr.py @@ -98,12 +98,12 @@ class AlwaysDispatchingPrettyPrinter(pprint.PrettyPrinter): level: int, ) -> None: # Type ignored because _dispatch is private. - p = self._dispatch.get(type(object).__repr__, None) # type: ignore[attr-defined] # noqa: F821 + p = self._dispatch.get(type(object).__repr__, None) # type: ignore[attr-defined] objid = id(object) if objid in context or p is None: # Type ignored because _format is private. - super()._format( # type: ignore[misc] # noqa: F821 + super()._format( # type: ignore[misc] object, stream, indent, allowance, context, level, ) return diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index 63126cbe0..3677d3bf9 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -146,7 +146,7 @@ class pytestPDB: # Type ignored because mypy doesn't support "dynamic" # inheritance like this. - class PytestPdbWrapper(pdb_cls): # type: ignore[valid-type,misc] # noqa: F821 + class PytestPdbWrapper(pdb_cls): # type: ignore[valid-type,misc] _pytest_capman = capman _continued = False @@ -349,7 +349,7 @@ def _enter_pdb( rep.toterminal(tw) tw.sep(">", "entering PDB") tb = _postmortem_traceback(excinfo) - rep._pdbshown = True # type: ignore[attr-defined] # noqa: F821 + rep._pdbshown = True # type: ignore[attr-defined] post_mortem(tb) return rep diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index 181c66b95..ebf0d584c 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -284,7 +284,7 @@ class DoctestItem(pytest.Item): failures = [] # type: List[doctest.DocTestFailure] # Type ignored because we change the type of `out` from what # doctest expects. - self.runner.run(self.dtest, out=failures) # type: ignore[arg-type] # noqa: F821 + self.runner.run(self.dtest, out=failures) # type: ignore[arg-type] if failures: raise MultipleDoctestFailures(failures) @@ -302,7 +302,7 @@ class DoctestItem(pytest.Item): sys.stderr.write(err) # TODO: Type ignored -- breaks Liskov Substitution. - def repr_failure( # type: ignore[override] # noqa: F821 + def repr_failure( # type: ignore[override] self, excinfo: ExceptionInfo[BaseException], ) -> Union[str, TerminalRepr]: import doctest @@ -329,7 +329,7 @@ class DoctestItem(pytest.Item): lineno = test.lineno + example.lineno + 1 message = type(failure).__name__ # TODO: ReprFileLocation doesn't expect a None lineno. - reprlocation = ReprFileLocation(filename, lineno, message) # type: ignore[arg-type] # noqa: F821 + reprlocation = ReprFileLocation(filename, lineno, message) # type: ignore[arg-type] checker = _get_checker() report_choice = _get_report_choice( self.config.getoption("doctestreport") @@ -567,9 +567,9 @@ def _setup_fixtures(doctest_item: DoctestItem) -> FixtureRequest: def func() -> None: pass - doctest_item.funcargs = {} # type: ignore[attr-defined] # noqa: F821 + doctest_item.funcargs = {} # type: ignore[attr-defined] fm = doctest_item.session._fixturemanager - doctest_item._fixtureinfo = fm.getfixtureinfo( # type: ignore[attr-defined] # noqa: F821 + doctest_item._fixtureinfo = fm.getfixtureinfo( # type: ignore[attr-defined] node=doctest_item, func=func, cls=None, funcargs=False ) fixture_request = FixtureRequest(doctest_item) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 52dc78b63..aef28a1ca 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -248,7 +248,7 @@ def get_parametrized_fixture_keys(item: "nodes.Item", scopenum: int) -> Iterator the specified scope. """ assert scopenum < scopenum_function # function try: - callspec = item.callspec # type: ignore[attr-defined] # noqa: F821 + callspec = item.callspec # type: ignore[attr-defined] except AttributeError: pass else: @@ -266,7 +266,7 @@ def get_parametrized_fixture_keys(item: "nodes.Item", scopenum: int) -> Iterator elif scopenum == 2: # module key = (argname, param_index, item.fspath) elif scopenum == 3: # class - item_cls = item.cls # type: ignore[attr-defined] # noqa: F821 + item_cls = item.cls # type: ignore[attr-defined] key = (argname, param_index, item.fspath, item_cls) yield key @@ -477,7 +477,7 @@ class FixtureRequest: fixturedefs = self._fixturemanager.getfixturedefs(argname, parentid) # TODO: Fix this type ignore. Either add assert or adjust types. # Can this be None here? - self._arg2fixturedefs[argname] = fixturedefs # type: ignore[assignment] # noqa: F821 + self._arg2fixturedefs[argname] = fixturedefs # type: ignore[assignment] # fixturedefs list is immutable so we maintain a decreasing index index = self._arg2index.get(argname, 0) - 1 if fixturedefs is None or (-index > len(fixturedefs)): @@ -723,7 +723,7 @@ class FixtureRequest: if scope == "package": # FIXME: _fixturedef is not defined on FixtureRequest (this class), # but on FixtureRequest (a subclass). - node = get_scope_package(self._pyfuncitem, self._fixturedef) # type: ignore[attr-defined] # noqa: F821 + node = get_scope_package(self._pyfuncitem, self._fixturedef) # type: ignore[attr-defined] else: node = get_scope_node(self._pyfuncitem, scope) if node is None and scope == "class": @@ -944,7 +944,7 @@ def _eval_scope_callable( try: # Type ignored because there is no typing mechanism to specify # keyword arguments, currently. - result = scope_callable(fixture_name=fixture_name, config=config) # type: ignore[call-arg] # noqa: F821 + result = scope_callable(fixture_name=fixture_name, config=config) # type: ignore[call-arg] except Exception as e: raise TypeError( "Error evaluating {} while defining fixture '{}'.\n" @@ -1081,7 +1081,7 @@ def resolve_fixture_function( if fixturedef.unittest: if request.instance is not None: # bind the unbound method to the TestCase instance - fixturefunc = fixturedef.func.__get__(request.instance) # type: ignore[union-attr] # noqa: F821 + fixturefunc = fixturedef.func.__get__(request.instance) # type: ignore[union-attr] else: # the fixture function needs to be bound to the actual # request.instance so that code working with "fixturedef" behaves @@ -1090,12 +1090,12 @@ def resolve_fixture_function( # handle the case where fixture is defined not in a test class, but some other class # (for example a plugin class with a fixture), see #2270 if hasattr(fixturefunc, "__self__") and not isinstance( - request.instance, fixturefunc.__self__.__class__ # type: ignore[union-attr] # noqa: F821 + request.instance, fixturefunc.__self__.__class__ # type: ignore[union-attr] ): return fixturefunc fixturefunc = getimfunc(fixturedef.func) if fixturefunc != fixturedef.func: - fixturefunc = fixturefunc.__get__(request.instance) # type: ignore[union-attr] # noqa: F821 + fixturefunc = fixturefunc.__get__(request.instance) # type: ignore[union-attr] return fixturefunc @@ -1167,7 +1167,7 @@ def wrap_function_to_error_out_if_called_directly(function, fixture_marker): # keep reference to the original function in our own custom attribute so we don't unwrap # further than this point and lose useful wrappings like @mock.patch (#3774) - result.__pytest_wrapped__ = _PytestWrapper(function) # type: ignore[attr-defined] # noqa: F821 + result.__pytest_wrapped__ = _PytestWrapper(function) # type: ignore[attr-defined] return result @@ -1209,7 +1209,7 @@ class FixtureFunctionMarker: ) # Type ignored because https://github.com/python/mypy/issues/2087. - function._pytestfixturefunction = self # type: ignore[attr-defined] # noqa: F821 + function._pytestfixturefunction = self # type: ignore[attr-defined] return function @@ -1503,7 +1503,7 @@ class FixtureManager: def pytest_plugin_registered(self, plugin: _PluggyPlugin) -> None: nodeid = None try: - p = py.path.local(plugin.__file__) # type: ignore[attr-defined] # noqa: F821 + p = py.path.local(plugin.__file__) # type: ignore[attr-defined] except AttributeError: pass else: diff --git a/src/_pytest/junitxml.py b/src/_pytest/junitxml.py index 4873e722d..8c68d196a 100644 --- a/src/_pytest/junitxml.py +++ b/src/_pytest/junitxml.py @@ -281,7 +281,7 @@ class _NodeReporter: self.__dict__.clear() # Type ignored becuase mypy doesn't like overriding a method. # Also the return value doesn't match... - self.to_xml = lambda: py.xml.raw(data) # type: ignore # noqa: F821 + self.to_xml = lambda: py.xml.raw(data) # type: ignore def _warn_incompatibility_with_xunit2( diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index 52d75e66d..1df0643a6 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -165,7 +165,7 @@ class PercentStyleMultiline(logging.PercentStyle): if "\n" in record.message: if hasattr(record, "auto_indent"): # passed in from the "extra={}" kwarg on the call to logging.log() - auto_indent = self._get_auto_indent(record.auto_indent) # type: ignore[attr-defined] # noqa: F821 + auto_indent = self._get_auto_indent(record.auto_indent) # type: ignore[attr-defined] else: auto_indent = self._auto_indent @@ -755,7 +755,7 @@ class _LiveLoggingStreamHandler(logging.StreamHandler): :param _pytest.terminal.TerminalReporter terminal_reporter: :param _pytest.capture.CaptureManager capture_manager: """ - logging.StreamHandler.__init__(self, stream=terminal_reporter) # type: ignore[arg-type] # noqa: F821 + logging.StreamHandler.__init__(self, stream=terminal_reporter) # type: ignore[arg-type] self.capture_manager = capture_manager self.reset() self.set_when(None) diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index 0c9344f3f..38369388c 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -124,7 +124,7 @@ class ParameterSet( # # @pytest.mark.parametrize(('x', 'y'), [1, 2]) # def test_foo(x, y): pass - return cls(parameterset, marks=[], id=None) # type: ignore[arg-type] # noqa: F821 + return cls(parameterset, marks=[], id=None) # type: ignore[arg-type] @staticmethod def _parse_parametrize_args( @@ -320,7 +320,7 @@ class MarkDecorator: # return type. Not much we can do about that. Thankfully mypy picks # the first match so it works out even if we break the rules. @overload - def __call__(self, arg: _Markable) -> _Markable: # type: ignore[misc] # noqa: F821 + def __call__(self, arg: _Markable) -> _Markable: # type: ignore[misc] raise NotImplementedError() @overload # noqa: F811 diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index 24e466586..560548aea 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -457,7 +457,7 @@ class Collector(Node): raise NotImplementedError("abstract") # TODO: This omits the style= parameter which breaks Liskov Substitution. - def repr_failure( # type: ignore[override] # noqa: F821 + def repr_failure( # type: ignore[override] self, excinfo: ExceptionInfo[BaseException] ) -> Union[str, TerminalRepr]: """ @@ -600,7 +600,7 @@ class FSCollector(Collector): else: duplicate_paths.add(path) - return ihook.pytest_collect_file(path=path, parent=self) # type: ignore[no-any-return] # noqa: F723 + return ihook.pytest_collect_file(path=path, parent=self) # type: ignore[no-any-return] class File(FSCollector): diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 2c9f383e4..7209bf1ed 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -299,7 +299,7 @@ class PyobjMixin: """Gets the underlying Python object. May be overwritten by subclasses.""" # TODO: Improve the type of `parent` such that assert/ignore aren't needed. assert self.parent is not None - obj = self.parent.obj # type: ignore[attr-defined] # noqa: F821 + obj = self.parent.obj # type: ignore[attr-defined] return getattr(obj, self.name) def getmodpath(self, stopatmodule: bool = True, includemodule: bool = False) -> str: @@ -784,7 +784,7 @@ class Instance(PyCollector): def _getobj(self): # TODO: Improve the type of `parent` such that assert/ignore aren't needed. assert self.parent is not None - obj = self.parent.obj # type: ignore[attr-defined] # noqa: F821 + obj = self.parent.obj # type: ignore[attr-defined] return obj() def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]: @@ -1593,7 +1593,7 @@ class Function(PyobjMixin, nodes.Item): entry.set_repr_style("short") # TODO: Type ignored -- breaks Liskov Substitution. - def repr_failure( # type: ignore[override] # noqa: F821 + def repr_failure( # type: ignore[override] self, excinfo: ExceptionInfo[BaseException], ) -> Union[str, TerminalRepr]: style = self.config.getoption("tbstyle", "auto") diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index 49bb909cc..11ca571aa 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -165,7 +165,7 @@ class WarningsRecorder(warnings.catch_warnings): def __init__(self) -> None: # Type ignored due to the way typeshed handles warnings.catch_warnings. - super().__init__(record=True) # type: ignore[call-arg] # noqa: F821 + super().__init__(record=True) # type: ignore[call-arg] self._entered = False self._list = [] # type: List[warnings.WarningMessage] diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 702380a5b..69754ad5e 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -106,8 +106,8 @@ def runtestprotocol( item: Item, log: bool = True, nextitem: Optional[Item] = None ) -> List[TestReport]: hasrequest = hasattr(item, "_request") - if hasrequest and not item._request: # type: ignore[attr-defined] # noqa: F821 - item._initrequest() # type: ignore[attr-defined] # noqa: F821 + if hasrequest and not item._request: # type: ignore[attr-defined] + item._initrequest() # type: ignore[attr-defined] rep = call_and_report(item, "setup", log) reports = [rep] if rep.passed: @@ -119,8 +119,8 @@ def runtestprotocol( # after all teardown hooks have been called # want funcargs and request info to go away if hasrequest: - item._request = False # type: ignore[attr-defined] # noqa: F821 - item.funcargs = None # type: ignore[attr-defined] # noqa: F821 + item._request = False # type: ignore[attr-defined] + item.funcargs = None # type: ignore[attr-defined] return reports @@ -422,7 +422,7 @@ class SetupState: # check if the last collection node has raised an error for col in self.stack: if hasattr(col, "_prepare_exc"): - exc = col._prepare_exc # type: ignore[attr-defined] # noqa: F821 + exc = col._prepare_exc # type: ignore[attr-defined] raise exc needed_collectors = colitem.listchain() @@ -431,7 +431,7 @@ class SetupState: try: col.setup() except TEST_OUTCOME as e: - col._prepare_exc = e # type: ignore[attr-defined] # noqa: F821 + col._prepare_exc = e # type: ignore[attr-defined] raise e diff --git a/src/_pytest/setuponly.py b/src/_pytest/setuponly.py index 932d0c279..dfd01cc76 100644 --- a/src/_pytest/setuponly.py +++ b/src/_pytest/setuponly.py @@ -43,7 +43,7 @@ def pytest_fixture_setup( param = fixturedef.ids[request.param_index] else: param = request.param - fixturedef.cached_param = param # type: ignore[attr-defined] # noqa: F821 + fixturedef.cached_param = param # type: ignore[attr-defined] _show_fixture_action(fixturedef, "SETUP") @@ -53,7 +53,7 @@ def pytest_fixture_post_finalizer(fixturedef: FixtureDef) -> None: if config.option.setupshow: _show_fixture_action(fixturedef, "TEARDOWN") if hasattr(fixturedef, "cached_param"): - del fixturedef.cached_param # type: ignore[attr-defined] # noqa: F821 + del fixturedef.cached_param # type: ignore[attr-defined] def _show_fixture_action(fixturedef: FixtureDef, msg: str) -> None: diff --git a/src/_pytest/skipping.py b/src/_pytest/skipping.py index dca2466c4..335e10996 100644 --- a/src/_pytest/skipping.py +++ b/src/_pytest/skipping.py @@ -56,7 +56,7 @@ def pytest_configure(config: Config) -> None: def nop(*args, **kwargs): pass - nop.Exception = xfail.Exception # type: ignore[attr-defined] # noqa: F821 + nop.Exception = xfail.Exception # type: ignore[attr-defined] setattr(pytest, "xfail", nop) config.addinivalue_line( diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 6c19e56dd..ef9da50f3 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -1219,7 +1219,7 @@ def _get_line_with_reprcrash_message( try: # Type ignored intentionally -- possible AttributeError expected. - msg = rep.longrepr.reprcrash.message # type: ignore[union-attr] # noqa: F821 + msg = rep.longrepr.reprcrash.message # type: ignore[union-attr] except AttributeError: pass else: diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py index bd61726c7..782a5c369 100644 --- a/src/_pytest/unittest.py +++ b/src/_pytest/unittest.py @@ -102,13 +102,13 @@ class UnitTestCase(Class): cls, "setUpClass", "tearDownClass", scope="class", pass_self=False ) if class_fixture: - cls.__pytest_class_setup = class_fixture # type: ignore[attr-defined] # noqa: F821 + cls.__pytest_class_setup = class_fixture # type: ignore[attr-defined] method_fixture = _make_xunit_fixture( cls, "setup_method", "teardown_method", scope="function", pass_self=True ) if method_fixture: - cls.__pytest_method_setup = method_fixture # type: ignore[attr-defined] # noqa: F821 + cls.__pytest_method_setup = method_fixture # type: ignore[attr-defined] def _make_xunit_fixture( @@ -148,7 +148,7 @@ class TestCaseFunction(Function): # a bound method to be called during teardown() if set (see 'runtest()') self._explicit_tearDown = None # type: Optional[Callable[[], None]] assert self.parent is not None - self._testcase = self.parent.obj(self.name) # type: ignore[attr-defined] # noqa: F821 + self._testcase = self.parent.obj(self.name) # type: ignore[attr-defined] self._obj = getattr(self._testcase, self.name) if hasattr(self, "_request"): self._request._fillfixtures() @@ -167,7 +167,7 @@ class TestCaseFunction(Function): # unwrap potential exception info (see twisted trial support below) rawexcinfo = getattr(rawexcinfo, "_rawexcinfo", rawexcinfo) try: - excinfo = _pytest._code.ExceptionInfo(rawexcinfo) # type: ignore[arg-type] # noqa: F821 + excinfo = _pytest._code.ExceptionInfo(rawexcinfo) # type: ignore[arg-type] # invoke the attributes to trigger storing the traceback # trial causes some issue there excinfo.value @@ -259,7 +259,7 @@ class TestCaseFunction(Function): # let the unittest framework handle async functions if is_async_function(self.obj): # Type ignored because self acts as the TestResult, but is not actually one. - self._testcase(result=self) # type: ignore[arg-type] # noqa: F821 + self._testcase(result=self) # type: ignore[arg-type] else: # when --pdb is given, we want to postpone calling tearDown() otherwise # when entering the pdb prompt, tearDown() would have probably cleaned up @@ -275,7 +275,7 @@ class TestCaseFunction(Function): # wrap_pytest_function_for_tracing replaces self.obj by a wrapper setattr(self._testcase, self.name, self.obj) try: - self._testcase(result=self) # type: ignore[arg-type] # noqa: F821 + self._testcase(result=self) # type: ignore[arg-type] finally: delattr(self._testcase, self.name) diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 6ee848e54..060f52cc7 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -752,7 +752,7 @@ raise ValueError() from _pytest._code.code import Code monkeypatch.setattr(Code, "path", "bogus") - excinfo.traceback[0].frame.code.path = "bogus" # type: ignore[misc] # noqa: F821 + excinfo.traceback[0].frame.code.path = "bogus" # type: ignore[misc] p = FormattedExcinfo(style="short") reprtb = p.repr_traceback_entry(excinfo.traceback[-2]) lines = reprtb.lines diff --git a/testing/example_scripts/dataclasses/test_compare_two_different_dataclasses.py b/testing/example_scripts/dataclasses/test_compare_two_different_dataclasses.py index 22e981e33..0a4820c69 100644 --- a/testing/example_scripts/dataclasses/test_compare_two_different_dataclasses.py +++ b/testing/example_scripts/dataclasses/test_compare_two_different_dataclasses.py @@ -16,4 +16,4 @@ def test_comparing_two_different_data_classes() -> None: left = SimpleDataObjectOne(1, "b") right = SimpleDataObjectTwo(1, "c") - assert left != right # type: ignore[comparison-overlap] # noqa: F821 + assert left != right # type: ignore[comparison-overlap] diff --git a/testing/io/test_saferepr.py b/testing/io/test_saferepr.py index 6912a113f..7a97cf424 100644 --- a/testing/io/test_saferepr.py +++ b/testing/io/test_saferepr.py @@ -34,8 +34,8 @@ def test_exceptions() -> None: raise self.ex class BrokenReprException(Exception): - __str__ = None # type: ignore[assignment] # noqa: F821 - __repr__ = None # type: ignore[assignment] # noqa: F821 + __str__ = None # type: ignore[assignment] + __repr__ = None # type: ignore[assignment] assert "Exception" in saferepr(BrokenRepr(Exception("broken"))) s = saferepr(BrokenReprException("really broken")) @@ -44,7 +44,7 @@ def test_exceptions() -> None: none = None try: - none() # type: ignore[misc] # noqa: F821 + none() # type: ignore[misc] except BaseException as exc: exp_exc = repr(exc) obj = BrokenRepr(BrokenReprException("omg even worse")) @@ -139,7 +139,7 @@ def test_big_repr(): def test_repr_on_newstyle() -> None: class Function: def __repr__(self): - return "<%s>" % (self.name) # type: ignore[attr-defined] # noqa: F821 + return "<%s>" % (self.name) # type: ignore[attr-defined] assert saferepr(Function()) diff --git a/testing/python/collect.py b/testing/python/collect.py index 691380a0b..80c962d70 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -724,10 +724,10 @@ class TestSorting: assert fn1 != fn3 for fn in fn1, fn2, fn3: - assert fn != 3 # type: ignore[comparison-overlap] # noqa: F821 + assert fn != 3 # type: ignore[comparison-overlap] assert fn != modcol - assert fn != [1, 2, 3] # type: ignore[comparison-overlap] # noqa: F821 - assert [1, 2, 3] != fn # type: ignore[comparison-overlap] # noqa: F821 + assert fn != [1, 2, 3] # type: ignore[comparison-overlap] + assert [1, 2, 3] != fn # type: ignore[comparison-overlap] assert modcol != fn def test_allow_sane_sorting_for_decorators(self, testdir): diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index 3efbbe107..ca3408ece 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -3850,7 +3850,7 @@ class TestScopeOrdering: ) testdir.runpytest() # actual fixture execution differs: dependent fixtures must be created first ("my_tmpdir") - FIXTURE_ORDER = pytest.FIXTURE_ORDER # type: ignore[attr-defined] # noqa: F821 + FIXTURE_ORDER = pytest.FIXTURE_ORDER # type: ignore[attr-defined] assert FIXTURE_ORDER == "s1 my_tmpdir_factory p1 m1 my_tmpdir f1 f2".split() def test_func_closure_module(self, testdir): @@ -4159,7 +4159,7 @@ def test_fixture_duplicated_arguments() -> None: """Raise error if there are positional and keyword arguments for the same parameter (#1682).""" with pytest.raises(TypeError) as excinfo: - @pytest.fixture("session", scope="session") # type: ignore[call-overload] # noqa: F821 + @pytest.fixture("session", scope="session") # type: ignore[call-overload] def arg(arg): pass @@ -4171,7 +4171,7 @@ def test_fixture_duplicated_arguments() -> None: with pytest.raises(TypeError) as excinfo: - @pytest.fixture( # type: ignore[call-overload] # noqa: F821 + @pytest.fixture( # type: ignore[call-overload] "function", ["p1"], True, @@ -4199,7 +4199,7 @@ def test_fixture_with_positionals() -> None: with pytest.warns(pytest.PytestDeprecationWarning) as warnings: - @pytest.fixture("function", [0], True) # type: ignore[call-overload] # noqa: F821 + @pytest.fixture("function", [0], True) # type: ignore[call-overload] def fixture_with_positionals(): pass @@ -4213,7 +4213,7 @@ def test_fixture_with_positionals() -> None: def test_fixture_with_too_many_positionals() -> None: with pytest.raises(TypeError) as excinfo: - @pytest.fixture("function", [0], True, ["id"], "name", "extra") # type: ignore[call-overload] # noqa: F821 + @pytest.fixture("function", [0], True, ["id"], "name", "extra") # type: ignore[call-overload] def fixture_with_positionals(): pass diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 6a841a346..4e6cfaf91 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -77,7 +77,7 @@ class TestMetafunc: pytest.raises(ValueError, lambda: metafunc.parametrize("y", [5, 6])) with pytest.raises(TypeError, match="^ids must be a callable or an iterable$"): - metafunc.parametrize("y", [5, 6], ids=42) # type: ignore[arg-type] # noqa: F821 + metafunc.parametrize("y", [5, 6], ids=42) # type: ignore[arg-type] def test_parametrize_error_iterator(self) -> None: def func(x): @@ -95,7 +95,7 @@ class TestMetafunc: metafunc = self.Metafunc(func) # When the input is an iterator, only len(args) are taken, # so the bad Exc isn't reached. - metafunc.parametrize("x", [1, 2], ids=gen()) # type: ignore[arg-type] # noqa: F821 + metafunc.parametrize("x", [1, 2], ids=gen()) # type: ignore[arg-type] assert [(x.funcargs, x.id) for x in metafunc._calls] == [ ({"x": 1}, "0"), ({"x": 2}, "2"), @@ -107,7 +107,7 @@ class TestMetafunc: r" Exc\(from_gen\) \(type: \) at index 2" ), ): - metafunc.parametrize("x", [1, 2, 3], ids=gen()) # type: ignore[arg-type] # noqa: F821 + metafunc.parametrize("x", [1, 2, 3], ids=gen()) # type: ignore[arg-type] def test_parametrize_bad_scope(self) -> None: def func(x): @@ -118,7 +118,7 @@ class TestMetafunc: fail.Exception, match=r"parametrize\(\) call in func got an unexpected scope value 'doggy'", ): - metafunc.parametrize("x", [1], scope="doggy") # type: ignore[arg-type] # noqa: F821 + metafunc.parametrize("x", [1], scope="doggy") # type: ignore[arg-type] def test_parametrize_request_name(self, testdir: Testdir) -> None: """Show proper error when 'request' is used as a parameter name in parametrize (#6183)""" @@ -675,7 +675,7 @@ class TestMetafunc: fail.Exception, match="In func: expected Sequence or boolean for indirect, got dict", ): - metafunc.parametrize("x, y", [("a", "b")], indirect={}) # type: ignore[arg-type] # noqa: F821 + metafunc.parametrize("x, y", [("a", "b")], indirect={}) # type: ignore[arg-type] def test_parametrize_indirect_list_functional(self, testdir: Testdir) -> None: """ diff --git a/testing/python/raises.py b/testing/python/raises.py index e55eb6f54..3f378d015 100644 --- a/testing/python/raises.py +++ b/testing/python/raises.py @@ -8,7 +8,7 @@ from _pytest.outcomes import Failed class TestRaises: def test_check_callable(self) -> None: with pytest.raises(TypeError, match=r".* must be callable"): - pytest.raises(RuntimeError, "int('qwe')") # type: ignore[call-overload] # noqa: F821 + pytest.raises(RuntimeError, "int('qwe')") # type: ignore[call-overload] def test_raises(self): excinfo = pytest.raises(ValueError, int, "qwe") @@ -30,7 +30,7 @@ class TestRaises: def test_raises_falsey_type_error(self) -> None: with pytest.raises(TypeError): - with pytest.raises(AssertionError, match=0): # type: ignore[call-overload] # noqa: F821 + with pytest.raises(AssertionError, match=0): # type: ignore[call-overload] raise AssertionError("ohai") def test_raises_repr_inflight(self): @@ -128,11 +128,11 @@ class TestRaises: def test_noclass(self) -> None: with pytest.raises(TypeError): - pytest.raises("wrong", lambda: None) # type: ignore[call-overload] # noqa: F821 + pytest.raises("wrong", lambda: None) # type: ignore[call-overload] def test_invalid_arguments_to_raises(self) -> None: with pytest.raises(TypeError, match="unknown"): - with pytest.raises(TypeError, unknown="bogus"): # type: ignore[call-overload] # noqa: F821 + with pytest.raises(TypeError, unknown="bogus"): # type: ignore[call-overload] raise ValueError() def test_tuple(self): @@ -262,12 +262,12 @@ class TestRaises: assert False, "via __class__" with pytest.raises(AssertionError) as excinfo: - with pytest.raises(CrappyClass()): # type: ignore[call-overload] # noqa: F821 + with pytest.raises(CrappyClass()): # type: ignore[call-overload] pass assert "via __class__" in excinfo.value.args[0] def test_raises_context_manager_with_kwargs(self): with pytest.raises(TypeError) as excinfo: - with pytest.raises(Exception, foo="bar"): # type: ignore[call-overload] # noqa: F821 + with pytest.raises(Exception, foo="bar"): # type: ignore[call-overload] pass assert "Unexpected keyword arguments" in str(excinfo.value) diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 38893deb9..e403bb2ec 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -51,7 +51,7 @@ def getmsg( exec(code, ns) func = ns[f.__name__] try: - func() # type: ignore[operator] # noqa: F821 + func() # type: ignore[operator] except AssertionError: if must_pass: pytest.fail("shouldn't have raised") @@ -174,7 +174,7 @@ class TestAssertionRewrite: assert getmsg(f3, {"a_global": False}) == "assert False" def f4() -> None: - assert sys == 42 # type: ignore[comparison-overlap] # noqa: F821 + assert sys == 42 # type: ignore[comparison-overlap] verbose = request.config.getoption("verbose") msg = getmsg(f4, {"sys": sys}) @@ -188,7 +188,7 @@ class TestAssertionRewrite: assert msg == "assert sys == 42" def f5() -> None: - assert cls == 42 # type: ignore[name-defined] # noqa: F821 + assert cls == 42 # type: ignore[name-defined] # noqa: F821 class X: pass @@ -684,7 +684,7 @@ class TestAssertionRewrite: def test_formatchar(self) -> None: def f() -> None: - assert "%test" == "test" # type: ignore[comparison-overlap] # noqa: F821 + assert "%test" == "test" # type: ignore[comparison-overlap] msg = getmsg(f) assert msg is not None @@ -1264,7 +1264,7 @@ class TestEarlyRewriteBailout: # use default patterns, otherwise we inherit pytest's testing config hook.fnpats[:] = ["test_*.py", "*_test.py"] monkeypatch.setattr(hook, "_find_spec", spy_find_spec) - hook.set_session(StubSession()) # type: ignore[arg-type] # noqa: F821 + hook.set_session(StubSession()) # type: ignore[arg-type] testdir.syspathinsert() return hook diff --git a/testing/test_capture.py b/testing/test_capture.py index 9e5036a66..a3bd4b623 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -1537,7 +1537,7 @@ def test_encodedfile_writelines(tmpfile: BinaryIO) -> None: ef = capture.EncodedFile(tmpfile, encoding="utf-8") with pytest.raises(TypeError): ef.writelines([b"line1", b"line2"]) - assert ef.writelines(["line3", "line4"]) is None # type: ignore[func-returns-value] # noqa: F821 + assert ef.writelines(["line3", "line4"]) is None # type: ignore[func-returns-value] ef.flush() tmpfile.seek(0) assert tmpfile.read() == b"line3line4" diff --git a/testing/test_collection.py b/testing/test_collection.py index d7a9b0439..6bab509d0 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -41,10 +41,10 @@ class TestCollector: for fn in fn1, fn2, fn3: assert isinstance(fn, pytest.Function) - assert fn != 3 # type: ignore[comparison-overlap] # noqa: F821 + assert fn != 3 # type: ignore[comparison-overlap] assert fn != modcol - assert fn != [1, 2, 3] # type: ignore[comparison-overlap] # noqa: F821 - assert [1, 2, 3] != fn # type: ignore[comparison-overlap] # noqa: F821 + assert fn != [1, 2, 3] # type: ignore[comparison-overlap] + assert [1, 2, 3] != fn # type: ignore[comparison-overlap] assert modcol != fn assert testdir.collect_by_name(modcol, "doesnotexist") is None diff --git a/testing/test_config.py b/testing/test_config.py index 94cb3db5e..9b1c11d5e 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -1602,7 +1602,7 @@ def test_invocation_args(testdir): # args cannot be None with pytest.raises(TypeError): - Config.InvocationParams(args=None, plugins=None, dir=Path()) # type: ignore[arg-type] # noqa: F821 + Config.InvocationParams(args=None, plugins=None, dir=Path()) # type: ignore[arg-type] @pytest.mark.parametrize( diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 9ef9417cd..965dba6c1 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -1490,7 +1490,7 @@ def test_warning_on_unwrap_of_broken_object( pytest.PytestWarning, match="^Got KeyError.* when unwrapping" ): with pytest.raises(KeyError): - inspect.unwrap(bad_instance, stop=stop) # type: ignore[arg-type] # noqa: F821 + inspect.unwrap(bad_instance, stop=stop) # type: ignore[arg-type] assert inspect.unwrap.__module__ == "inspect" diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 5e5826b23..eb8475ca5 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -1124,7 +1124,7 @@ def test_unicode_issue368(testdir) -> None: node_reporter.append_skipped(test_report) test_report.longrepr = "filename", 1, "Skipped: 卡嘣嘣" node_reporter.append_skipped(test_report) - test_report.wasxfail = ustr # type: ignore[attr-defined] # noqa: F821 + test_report.wasxfail = ustr # type: ignore[attr-defined] node_reporter.append_skipped(test_report) log.pytest_sessionfinish() diff --git a/testing/test_mark.py b/testing/test_mark.py index f261c8922..f35660093 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -20,7 +20,7 @@ class TestMark: def test_pytest_mark_notcallable(self) -> None: mark = Mark() with pytest.raises(TypeError): - mark() # type: ignore[operator] # noqa: F821 + mark() # type: ignore[operator] def test_mark_with_param(self): def some_function(abc): @@ -31,10 +31,10 @@ class TestMark: assert pytest.mark.foo(some_function) is some_function marked_with_args = pytest.mark.foo.with_args(some_function) - assert marked_with_args is not some_function # type: ignore[comparison-overlap] # noqa: F821 + assert marked_with_args is not some_function # type: ignore[comparison-overlap] assert pytest.mark.foo(SomeClass) is SomeClass - assert pytest.mark.foo.with_args(SomeClass) is not SomeClass # type: ignore[comparison-overlap] # noqa: F821 + assert pytest.mark.foo.with_args(SomeClass) is not SomeClass # type: ignore[comparison-overlap] def test_pytest_mark_name_starts_with_underscore(self): mark = Mark() @@ -1077,7 +1077,7 @@ def test_markers_from_parametrize(testdir): def test_pytest_param_id_requires_string() -> None: with pytest.raises(TypeError) as excinfo: - pytest.param(id=True) # type: ignore[arg-type] # noqa: F821 + pytest.param(id=True) # type: ignore[arg-type] (msg,) = excinfo.value.args assert msg == "Expected id to be a string, got : True" diff --git a/testing/test_nodes.py b/testing/test_nodes.py index cc6e562a5..f9026ec61 100644 --- a/testing/test_nodes.py +++ b/testing/test_nodes.py @@ -25,9 +25,9 @@ def test_ischildnode(baseid: str, nodeid: str, expected: bool) -> None: def test_node_from_parent_disallowed_arguments() -> None: with pytest.raises(TypeError, match="session is"): - nodes.Node.from_parent(None, session=None) # type: ignore[arg-type] # noqa: F821 + nodes.Node.from_parent(None, session=None) # type: ignore[arg-type] with pytest.raises(TypeError, match="config is"): - nodes.Node.from_parent(None, config=None) # type: ignore[arg-type] # noqa: F821 + nodes.Node.from_parent(None, config=None) # type: ignore[arg-type] def test_std_warn_not_pytestwarning(testdir: Testdir) -> None: diff --git a/testing/test_pytester.py b/testing/test_pytester.py index d0afb40b0..46f3e1cab 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -484,20 +484,20 @@ def test_linematcher_with_nonlist() -> None: lm = LineMatcher([]) with pytest.raises(TypeError, match="invalid type for lines2: set"): - lm.fnmatch_lines(set()) # type: ignore[arg-type] # noqa: F821 + lm.fnmatch_lines(set()) # type: ignore[arg-type] with pytest.raises(TypeError, match="invalid type for lines2: dict"): - lm.fnmatch_lines({}) # type: ignore[arg-type] # noqa: F821 + lm.fnmatch_lines({}) # type: ignore[arg-type] with pytest.raises(TypeError, match="invalid type for lines2: set"): - lm.re_match_lines(set()) # type: ignore[arg-type] # noqa: F821 + lm.re_match_lines(set()) # type: ignore[arg-type] with pytest.raises(TypeError, match="invalid type for lines2: dict"): - lm.re_match_lines({}) # type: ignore[arg-type] # noqa: F821 + lm.re_match_lines({}) # type: ignore[arg-type] with pytest.raises(TypeError, match="invalid type for lines2: Source"): - lm.fnmatch_lines(Source()) # type: ignore[arg-type] # noqa: F821 + lm.fnmatch_lines(Source()) # type: ignore[arg-type] lm.fnmatch_lines([]) lm.fnmatch_lines(()) lm.fnmatch_lines("") - assert lm._getlines({}) == {} # type: ignore[arg-type,comparison-overlap] # noqa: F821 - assert lm._getlines(set()) == set() # type: ignore[arg-type,comparison-overlap] # noqa: F821 + assert lm._getlines({}) == {} # type: ignore[arg-type,comparison-overlap] + assert lm._getlines(set()) == set() # type: ignore[arg-type,comparison-overlap] assert lm._getlines(Source()) == [] assert lm._getlines(Source("pass\npass")) == ["pass", "pass"] diff --git a/testing/test_runner.py b/testing/test_runner.py index 474ff4df8..def3f910d 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -884,7 +884,7 @@ def test_store_except_info_on_error() -> None: raise IndexError("TEST") try: - runner.pytest_runtest_call(ItemMightRaise()) # type: ignore[arg-type] # noqa: F821 + runner.pytest_runtest_call(ItemMightRaise()) # type: ignore[arg-type] except IndexError: pass # Check that exception info is stored on sys @@ -895,7 +895,7 @@ def test_store_except_info_on_error() -> None: # The next run should clear the exception info stored by the previous run ItemMightRaise.raise_error = False - runner.pytest_runtest_call(ItemMightRaise()) # type: ignore[arg-type] # noqa: F821 + runner.pytest_runtest_call(ItemMightRaise()) # type: ignore[arg-type] assert not hasattr(sys, "last_type") assert not hasattr(sys, "last_value") assert not hasattr(sys, "last_traceback") diff --git a/testing/test_store.py b/testing/test_store.py index 98014887e..b6d4208a0 100644 --- a/testing/test_store.py +++ b/testing/test_store.py @@ -47,7 +47,7 @@ def test_store() -> None: # Can't accidentally add attributes to store object itself. with pytest.raises(AttributeError): - store.foo = "nope" # type: ignore[attr-defined] # noqa: F821 + store.foo = "nope" # type: ignore[attr-defined] # No interaction with anoter store. store2 = Store() diff --git a/testing/test_terminal.py b/testing/test_terminal.py index f1481dce5..19aff9954 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1699,7 +1699,7 @@ def test_summary_stats( class fake_session: testscollected = 0 - tr._session = fake_session # type: ignore[assignment] # noqa: F821 + tr._session = fake_session # type: ignore[assignment] assert tr._is_last_item # Reset cache.