Skip to content

Commit ac428f6

Browse files
author
sousajo
committed
#8204 migrate tests on testing/code/test_source to tmp_path
1 parent 7585221 commit ac428f6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

testing/code/test_source.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from _pytest._code import Frame
1818
from _pytest._code import getfslineno
1919
from _pytest._code import Source
20+
from _pytest.pathlib import import_path
2021

2122

2223
def test_source_str_function() -> None:
@@ -285,7 +286,9 @@ def g():
285286
assert lines == ["def f():", " def g():", " pass"]
286287

287288

288-
def test_source_of_class_at_eof_without_newline(tmpdir, _sys_snapshot) -> None:
289+
def test_source_of_class_at_eof_without_newline(
290+
tmpdir, _sys_snapshot, tmp_path: Path
291+
) -> None:
289292
# this test fails because the implicit inspect.getsource(A) below
290293
# does not return the "x = 1" last line.
291294
source = Source(
@@ -295,9 +298,10 @@ def method(self):
295298
x = 1
296299
"""
297300
)
298-
path = tmpdir.join("a.py")
299-
path.write(source)
300-
s2 = Source(tmpdir.join("a.py").pyimport().A)
301+
path = tmp_path.joinpath("a.py")
302+
path.write_text(str(source))
303+
mod: Any = import_path(path)
304+
s2 = Source(mod.A)
301305
assert str(source).strip() == str(s2).strip()
302306

303307

0 commit comments

Comments
 (0)