From ac428f67ebb2469d91476cbe8ec7e10da6f6b106 Mon Sep 17 00:00:00 2001 From: sousajo Date: Fri, 1 Jan 2021 16:55:03 +0000 Subject: [PATCH] pytest-dev#8204 migrate tests on testing/code/test_source to tmp_path --- testing/code/test_source.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/testing/code/test_source.py b/testing/code/test_source.py index 6b8443fd2..083a7911f 100644 --- a/testing/code/test_source.py +++ b/testing/code/test_source.py @@ -17,6 +17,7 @@ from _pytest._code import Code from _pytest._code import Frame from _pytest._code import getfslineno from _pytest._code import Source +from _pytest.pathlib import import_path def test_source_str_function() -> None: @@ -285,7 +286,9 @@ def test_deindent() -> None: assert lines == ["def f():", " def g():", " pass"] -def test_source_of_class_at_eof_without_newline(tmpdir, _sys_snapshot) -> None: +def test_source_of_class_at_eof_without_newline( + tmpdir, _sys_snapshot, tmp_path: Path +) -> None: # this test fails because the implicit inspect.getsource(A) below # does not return the "x = 1" last line. source = Source( @@ -295,9 +298,10 @@ def test_source_of_class_at_eof_without_newline(tmpdir, _sys_snapshot) -> None: x = 1 """ ) - path = tmpdir.join("a.py") - path.write(source) - s2 = Source(tmpdir.join("a.py").pyimport().A) + path = tmp_path.joinpath("a.py") + path.write_text(str(source)) + mod: Any = import_path(path) + s2 = Source(mod.A) assert str(source).strip() == str(s2).strip()