Skip to content

pytester: _makefile: use abs=True when joining paths #6578

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def to_text(s):

ret = None
for basename, value in items:
p = self.tmpdir.join(basename).new(ext=ext)
p = self.tmpdir.join(basename, abs=True).new(ext=ext)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a breaking change that opens up badly made test suites to accidentally writing system wide files

the pathlib behaviour is a security nightmare as is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RonnyPfannschmidt
So what changes do you request then actually?
The use case here is using testdir.makepyfile with an absolute file - do you think this should not be supported then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing the current behavior in #6579.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current behavior fails on Windows:

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\Users\runneradmin\AppData\Local\Temp\pytest-of-runneradmin\pytest-0\popen-gw1\test_makefile_joins_absolute_path0\C:'

p.dirpath().ensure_dir()
source = Source(value)
source = "\n".join(to_text(line) for line in source.lines)
Expand Down
6 changes: 6 additions & 0 deletions testing/test_pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,3 +710,9 @@ def test_error2(bad_fixture):
result.assert_outcomes(error=2)

assert result.parseoutcomes() == {"error": 2}


def test_makefile_abs(testdir):
path = str(testdir.tmpdir / "absfile")
p1 = testdir.makepyfile(**{path: "..."})
assert str(p1) == path + ".py"