File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 17
17
from _pytest ._code import Frame
18
18
from _pytest ._code import getfslineno
19
19
from _pytest ._code import Source
20
+ from _pytest .pathlib import import_path
20
21
21
22
22
23
def test_source_str_function () -> None :
@@ -285,7 +286,9 @@ def g():
285
286
assert lines == ["def f():" , " def g():" , " pass" ]
286
287
287
288
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 :
289
292
# this test fails because the implicit inspect.getsource(A) below
290
293
# does not return the "x = 1" last line.
291
294
source = Source (
@@ -295,9 +298,10 @@ def method(self):
295
298
x = 1
296
299
"""
297
300
)
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 )
301
305
assert str (source ).strip () == str (s2 ).strip ()
302
306
303
307
You can’t perform that action at this time.
0 commit comments