Skip to content

tests: move test_getfslineno back #6623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions testing/code/test_code.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import inspect
import sys
from types import FrameType
from unittest import mock

import py.path

import pytest
from _pytest._code import Code
from _pytest._code import ExceptionInfo
from _pytest._code import Frame
from _pytest._code import getfslineno
from _pytest._code.code import ReprFuncArgs


Expand Down Expand Up @@ -184,32 +180,3 @@ def test_not_raise_exception_with_mixed_encoding(self, tw_mock) -> None:
tw_mock.lines[0]
== r"unicode_string = São Paulo, utf8_string = b'S\xc3\xa3o Paulo'"
)


def test_getfslineno() -> None:
def f(x) -> None:
raise NotImplementedError()

fspath, lineno = getfslineno(f)

assert isinstance(fspath, py.path.local)
assert fspath.basename == "test_code.py"
assert lineno == f.__code__.co_firstlineno - 1 # see findsource

class A:
pass

fspath, lineno = getfslineno(A)

_, A_lineno = inspect.findsource(A)
assert isinstance(fspath, py.path.local)
assert fspath.basename == "test_code.py"
assert lineno == A_lineno

assert getfslineno(3) == ("", -1)

class B:
pass

B.__name__ = "B2"
assert getfslineno(B)[1] == -1
32 changes: 31 additions & 1 deletion testing/code/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
from typing import Dict
from typing import Optional

import py
import py.path

import _pytest._code
import pytest
from _pytest._code import getfslineno
from _pytest._code import Source


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


def test_getfslineno() -> None:
def f(x) -> None:
raise NotImplementedError()

fspath, lineno = getfslineno(f)

assert isinstance(fspath, py.path.local)
assert fspath.basename == "test_source.py"
assert lineno == f.__code__.co_firstlineno - 1 # see findsource

class A:
pass

fspath, lineno = getfslineno(A)

_, A_lineno = inspect.findsource(A)
assert isinstance(fspath, py.path.local)
assert fspath.basename == "test_source.py"
assert lineno == A_lineno

assert getfslineno(3) == ("", -1)

class B:
pass

B.__name__ = "B2"
assert getfslineno(B)[1] == -1


def test_code_of_object_instance_with_call() -> None:
class A:
pass
Expand Down