Skip to content

Commit 78eddcb

Browse files
committed
tests: move test_getfslineno back
Reverts #6610. The tested `getfslineno` is `src/_pytest/_code/source.py` actually, exported via `src/_pytest/_code/__init__.py`. I've confused it with the one in `src/_pytest/compat.py` apparently.
1 parent 6633044 commit 78eddcb

File tree

2 files changed

+31
-34
lines changed

2 files changed

+31
-34
lines changed

testing/code/test_code.py

-33
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
import inspect
21
import sys
32
from types import FrameType
43
from unittest import mock
54

6-
import py.path
7-
85
import pytest
96
from _pytest._code import Code
107
from _pytest._code import ExceptionInfo
118
from _pytest._code import Frame
12-
from _pytest._code import getfslineno
139
from _pytest._code.code import ReprFuncArgs
1410

1511

@@ -184,32 +180,3 @@ def test_not_raise_exception_with_mixed_encoding(self, tw_mock) -> None:
184180
tw_mock.lines[0]
185181
== r"unicode_string = São Paulo, utf8_string = b'S\xc3\xa3o Paulo'"
186182
)
187-
188-
189-
def test_getfslineno() -> None:
190-
def f(x) -> None:
191-
raise NotImplementedError()
192-
193-
fspath, lineno = getfslineno(f)
194-
195-
assert isinstance(fspath, py.path.local)
196-
assert fspath.basename == "test_code.py"
197-
assert lineno == f.__code__.co_firstlineno - 1 # see findsource
198-
199-
class A:
200-
pass
201-
202-
fspath, lineno = getfslineno(A)
203-
204-
_, A_lineno = inspect.findsource(A)
205-
assert isinstance(fspath, py.path.local)
206-
assert fspath.basename == "test_code.py"
207-
assert lineno == A_lineno
208-
209-
assert getfslineno(3) == ("", -1)
210-
211-
class B:
212-
pass
213-
214-
B.__name__ = "B2"
215-
assert getfslineno(B)[1] == -1

testing/code/test_source.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
from typing import Dict
1010
from typing import Optional
1111

12-
import py
12+
import py.path
1313

1414
import _pytest._code
1515
import pytest
16+
from _pytest._code import getfslineno
1617
from _pytest._code import Source
1718

1819

@@ -495,6 +496,35 @@ def x():
495496
assert src[lineno] == " def x():"
496497

497498

499+
def test_getfslineno() -> None:
500+
def f(x) -> None:
501+
raise NotImplementedError()
502+
503+
fspath, lineno = getfslineno(f)
504+
505+
assert isinstance(fspath, py.path.local)
506+
assert fspath.basename == "test_source.py"
507+
assert lineno == f.__code__.co_firstlineno - 1 # see findsource
508+
509+
class A:
510+
pass
511+
512+
fspath, lineno = getfslineno(A)
513+
514+
_, A_lineno = inspect.findsource(A)
515+
assert isinstance(fspath, py.path.local)
516+
assert fspath.basename == "test_source.py"
517+
assert lineno == A_lineno
518+
519+
assert getfslineno(3) == ("", -1)
520+
521+
class B:
522+
pass
523+
524+
B.__name__ = "B2"
525+
assert getfslineno(B)[1] == -1
526+
527+
498528
def test_code_of_object_instance_with_call() -> None:
499529
class A:
500530
pass

0 commit comments

Comments
 (0)