Merge pull request #11799 from bluetech/rm-nose-compat_co_firstlineno

python: remove support for nose's `compat_co_firstlineno`
This commit is contained in:
Ran Benita 2024-01-11 13:13:30 +02:00 committed by GitHub
commit bd58c09500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 14 deletions

View File

@ -387,6 +387,13 @@ Will also need to be ported to a supported pytest style. One way to do it is usi
.. _`with-setup-nose`: https://nose.readthedocs.io/en/latest/testing_tools.html?highlight=with_setup#nose.tools.with_setup
The ``compat_co_firstlineno`` attribute
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Nose inspects this attribute on function objects to allow overriding the function's inferred line number.
Pytest no longer respects this attribute.
Passing ``msg=`` to ``pytest.skip``, ``pytest.fail`` or ``pytest.exit``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -6,7 +6,6 @@ import fnmatch
import inspect
import itertools
import os
import sys
import types
import warnings
from collections import Counter
@ -350,20 +349,8 @@ class PyobjMixin(nodes.Node):
def reportinfo(self) -> Tuple[Union["os.PathLike[str]", str], Optional[int], str]:
# XXX caching?
obj = self.obj
compat_co_firstlineno = getattr(obj, "compat_co_firstlineno", None)
if isinstance(compat_co_firstlineno, int):
# nose compatibility
file_path = sys.modules[obj.__module__].__file__
assert file_path is not None
if file_path.endswith(".pyc"):
file_path = file_path[:-1]
path: Union["os.PathLike[str]", str] = file_path
lineno = compat_co_firstlineno
else:
path, lineno = getfslineno(obj)
path, lineno = getfslineno(self.obj)
modpath = self.getmodpath()
assert isinstance(lineno, int)
return path, lineno, modpath