-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
pytester: testdir: add makefiles helper #6603
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
Conversation
b67b1cc
to
155651f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should this be allowed to accidentially allow writes outside?
From My pov this should fail on escape unless explicitly requested,
6715b20
to
9f534eb
Compare
40c0b66
to
712ac26
Compare
(Did not notice this PR when replying to #6579). I'm also interested in the use case to allow writing to absolute paths... I mean the user can just as easily write the files themselves (just missing the automatic |
This could look much nicer with it: pytest/testing/python/fixtures.py Lines 3628 to 3654 in 712ac26
The helper however is also about getting sane behavior in general, i.e. with regard to extensions and the return value. |
This is a sane method to create a set of files, allowing for absolute paths. Ref: pytest-dev#6578 Ref: pytest-dev#6579
712ac26
to
67b1161
Compare
Sorry if I'm missing something, but you would still be writing to files inside the |
What do you mean? The example above is writing to files in tmpdir, yes, but would pass absolute paths (inside of tmpdir), which currently get concatenated with |
As proposed and explained the implementation is a no go There are ways to do this that don't add a safety off footgun |
@RonnyPfannschmidt |
i missed the force push on my mobile earlier today |
this still doesn't answer however why to do the dance for allowing it, what's the use-case |
You got my point correctly: you would still be writing files inside the In the lack of a good use case, this only seems to add a feature that nobody should ever use, I believe this is also @RonnyPfannschmidt's concerns. |
Ok, might remove the |
I don't think the problem is a detail of implementation, but the feature in general.
Can you provide one or more use cases where this feature would be beneficial? The only one you provided would still write inside
As I see it, adding an explicit option to it or even to allow users to do it is to encourage a bad practice: users might be end up writing outside Recently we even added a check against this type of usage in |
@nicoddemus the main problem is that makepyfile etc join an given absolute path, therefore not allowing "/tmpdir/foo", but using "/tmpdir/tmpdir/foo" then (and failing on Windows).
E.g. changing "/etc/hosts" with dockerized/sandboxed tests?
Yeah, I can remove the flag (as said already). But it is not really "by mistake" if you explicitly enable it, is it?
It should not be necessary to make them relative before however, no? This could also be addressed with the existing |
Sorry, unless there's a good use case, I don't see this as a good thing.
This is a very convoluted example IMO, the user should be mocking this somehow and passing a temporary So this is a bad example IMO, because it is a bad written test. Users should be able to do it? Sure, it is their code, but that's not A bad practice should not be encouraged by the API, on the contrary.
Good, on that we agree. 😉
They are relative already and it would be more work to make them absolute and still safe. Can you rewrite the test and post it here (it doesn't even need to pass) to showcase what you see as an improvement? In summary, I don't like this idea because:
I'm curious though if I'm missing a good case for this or if I am thinking too hard about it, so would like to hear other's opinions. @bluetech @asottile @The-Compiler, what's your take on this? |
I agree with @nicoddemus on all fronts, well stated |
?? "tmpdir" is not "anywhere in the file system". Do you see that
Yeah. Since it can be done anyway, why not allow it via a flag then?
They are not relative. Passing in
Currently the test needs to look like this to be "improved": tests_dir = testdir.mkdir("tests")
fixdir = testdir.mkdir("fixtures")
fixfile = fixdir.join("fix.py")
testfile = tests_dir.join("test_foos.py")
testdir.makepyfile(
**{
fixfile.relto(
testdir.tmpdir
): """
…
""",
testfile.relto(
testdir.tmpdir
): """
…
""",
}
) (Note that this only works because With testdir.makefiles(
{
fixfile: """
…
""",
testfile: """
…
""",
}
)
See above.
But having to make a path below "tmpdir" explicitly relative should not be necessary, if it is an absolute path below it. |
The real problem is with
|
This I'm not against: ensure all paths given (relative or absolute) are below The confusing part about this conversation (to me at least) that you kept saying you wanted to pass absolute paths, implying that you wanted to write files outside So you can see why I was against the proposal: all lead me to believe that you wanted to write outside the |
JFI: this is not a war.
You might have wanted to elaborate, since it turned out @nicoddemus has missed the point several times, and got deadlocked on the "this can allow for arbitrary files outside tmpdir" (which was something I agreed on to remove already several times). |
Just for reference: I will likely take this into my fork then - keeping Since apart from all that I still think that |
@nicoddemus You might all might want to read up from the beginning before replying. But since I've closed this (also against out of frustration), you can also just ignore my comments (or rather just don't reply). |
@blueyed, I did follow the thread from the beginning. The absolute first question raised was from @RonnyPfannschmidt:
When I asked for a use case, then you wrote:
And went on showing an example which did not use absolute paths at all, nor was obvious why using absolute paths would make it better. Later on I said:
Instead of providing an example why that would be beneficial, you went on again about writing outside
And when asked for an example, you again mentioned writing outside
My main concern through the entire thread was not about "absolute paths" per-se, but writing outside the When you finally explicitly showed the use case you had in mind (in #6603 (comment)), then things got clear: it was never about writing outside @blueyed if I was the only one on this thread "not reading it carefully" as you imply and the only one who kept getting it "wrong", I would definitely be apologizing. But you really should take a step back and realize that other 2 people also misunderstood what you were saying, so perhaps the problem is not me, but how you present your ideas? And finally, when things were clear that allowing passing absolute paths was fine if we didn't allow absolute paths outside Spending all the time and effort in this discussion, to see it going unresolved even after we have reached a suitable conclusion, is very frunstrating, insatisfying, and frankly draining. |
Which was legitimate, and addressed right away (#6603 (comment)).
That's actually wrong.. it uses absolute paths. And that is the point you are missing..! Therefore I think the rest of your comment is based on having missed the point from there on already. I will reply to the rest via email. |
Never got that email, btw. |
This is a sane method to create a set of files, allowing for absolute
paths.
TODO:
Ref: #6578
Ref: #6579