internal: clean up getfslineno
Everything was using `_pytest.compat.getfslineno` basically, which wrapped `_pytest._code.source.getfslineno`. This moves the extra code from there into it directly, and uses the latter everywhere. This helps to eventually remove the one in compat eventually, and also causes less cyclic imports.
This commit is contained in:
parent
1480aa31a7
commit
b0d45267c5
|
@ -17,6 +17,7 @@ from typing import Union
|
||||||
|
|
||||||
import py
|
import py
|
||||||
|
|
||||||
|
from _pytest.compat import get_real_func
|
||||||
from _pytest.compat import overload
|
from _pytest.compat import overload
|
||||||
from _pytest.compat import TYPE_CHECKING
|
from _pytest.compat import TYPE_CHECKING
|
||||||
|
|
||||||
|
@ -290,6 +291,13 @@ def getfslineno(obj) -> Tuple[Optional[Union["Literal['']", py.path.local]], int
|
||||||
"""
|
"""
|
||||||
from .code import Code
|
from .code import Code
|
||||||
|
|
||||||
|
# xxx let decorators etc specify a sane ordering
|
||||||
|
# NOTE: this used to be done in _pytest.compat.getfslineno, initially added
|
||||||
|
# in 6ec13a2b9. It ("place_as") appears to be something very custom.
|
||||||
|
obj = get_real_func(obj)
|
||||||
|
if hasattr(obj, "place_as"):
|
||||||
|
obj = obj.place_as
|
||||||
|
|
||||||
try:
|
try:
|
||||||
code = Code(obj)
|
code = Code(obj)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
|
|
@ -22,7 +22,6 @@ from typing import Union
|
||||||
import attr
|
import attr
|
||||||
import py
|
import py
|
||||||
|
|
||||||
import _pytest
|
|
||||||
from _pytest._io.saferepr import saferepr
|
from _pytest._io.saferepr import saferepr
|
||||||
from _pytest.outcomes import fail
|
from _pytest.outcomes import fail
|
||||||
from _pytest.outcomes import TEST_OUTCOME
|
from _pytest.outcomes import TEST_OUTCOME
|
||||||
|
@ -308,13 +307,10 @@ def get_real_method(obj, holder):
|
||||||
|
|
||||||
|
|
||||||
def getfslineno(obj) -> Tuple[Union[str, py.path.local], int]:
|
def getfslineno(obj) -> Tuple[Union[str, py.path.local], int]:
|
||||||
# xxx let decorators etc specify a sane ordering
|
"""(**Deprecated**, use _pytest._code.source.getfslineno directly)"""
|
||||||
obj = get_real_func(obj)
|
from _pytest._code.source import getfslineno
|
||||||
if hasattr(obj, "place_as"):
|
|
||||||
obj = obj.place_as
|
return getfslineno(obj)
|
||||||
fslineno = _pytest._code.getfslineno(obj)
|
|
||||||
assert isinstance(fslineno[1], int), obj
|
|
||||||
return fslineno
|
|
||||||
|
|
||||||
|
|
||||||
def getimfunc(func):
|
def getimfunc(func):
|
||||||
|
|
|
@ -16,12 +16,12 @@ import py
|
||||||
import _pytest
|
import _pytest
|
||||||
from _pytest._code.code import FormattedExcinfo
|
from _pytest._code.code import FormattedExcinfo
|
||||||
from _pytest._code.code import TerminalRepr
|
from _pytest._code.code import TerminalRepr
|
||||||
|
from _pytest._code.source import getfslineno
|
||||||
from _pytest._io import TerminalWriter
|
from _pytest._io import TerminalWriter
|
||||||
from _pytest.compat import _format_args
|
from _pytest.compat import _format_args
|
||||||
from _pytest.compat import _PytestWrapper
|
from _pytest.compat import _PytestWrapper
|
||||||
from _pytest.compat import get_real_func
|
from _pytest.compat import get_real_func
|
||||||
from _pytest.compat import get_real_method
|
from _pytest.compat import get_real_method
|
||||||
from _pytest.compat import getfslineno
|
|
||||||
from _pytest.compat import getfuncargnames
|
from _pytest.compat import getfuncargnames
|
||||||
from _pytest.compat import getimfunc
|
from _pytest.compat import getimfunc
|
||||||
from _pytest.compat import getlocation
|
from _pytest.compat import getlocation
|
||||||
|
|
|
@ -6,9 +6,9 @@ from typing import Set
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
|
||||||
|
from .._code.source import getfslineno
|
||||||
from ..compat import ascii_escaped
|
from ..compat import ascii_escaped
|
||||||
from ..compat import ATTRS_EQ_FIELD
|
from ..compat import ATTRS_EQ_FIELD
|
||||||
from ..compat import getfslineno
|
|
||||||
from ..compat import NOTSET
|
from ..compat import NOTSET
|
||||||
from _pytest.outcomes import fail
|
from _pytest.outcomes import fail
|
||||||
from _pytest.warning_types import PytestUnknownMarkWarning
|
from _pytest.warning_types import PytestUnknownMarkWarning
|
||||||
|
|
|
@ -15,8 +15,8 @@ import _pytest._code
|
||||||
from _pytest._code.code import ExceptionChainRepr
|
from _pytest._code.code import ExceptionChainRepr
|
||||||
from _pytest._code.code import ExceptionInfo
|
from _pytest._code.code import ExceptionInfo
|
||||||
from _pytest._code.code import ReprExceptionInfo
|
from _pytest._code.code import ReprExceptionInfo
|
||||||
|
from _pytest._code.source import getfslineno
|
||||||
from _pytest.compat import cached_property
|
from _pytest.compat import cached_property
|
||||||
from _pytest.compat import getfslineno
|
|
||||||
from _pytest.compat import TYPE_CHECKING
|
from _pytest.compat import TYPE_CHECKING
|
||||||
from _pytest.config import Config
|
from _pytest.config import Config
|
||||||
from _pytest.config import PytestPluginManager
|
from _pytest.config import PytestPluginManager
|
||||||
|
|
|
@ -20,10 +20,10 @@ import _pytest
|
||||||
from _pytest import fixtures
|
from _pytest import fixtures
|
||||||
from _pytest import nodes
|
from _pytest import nodes
|
||||||
from _pytest._code import filter_traceback
|
from _pytest._code import filter_traceback
|
||||||
|
from _pytest._code.source import getfslineno
|
||||||
from _pytest.compat import ascii_escaped
|
from _pytest.compat import ascii_escaped
|
||||||
from _pytest.compat import get_default_arg_names
|
from _pytest.compat import get_default_arg_names
|
||||||
from _pytest.compat import get_real_func
|
from _pytest.compat import get_real_func
|
||||||
from _pytest.compat import getfslineno
|
|
||||||
from _pytest.compat import getimfunc
|
from _pytest.compat import getimfunc
|
||||||
from _pytest.compat import getlocation
|
from _pytest.compat import getlocation
|
||||||
from _pytest.compat import is_generator
|
from _pytest.compat import is_generator
|
||||||
|
|
Loading…
Reference in New Issue