[Python-Dev] Adding test.support.safe_rmpath()
steve.dower at python.org
Fri Feb 15 12:43:13 EST 2019
On 14Feb.2019 0948, Brett Cannon wrote:
> On Thu, Feb 14, 2019 at 7:26 AM Giampaolo Rodola' <g.rodola at gmail.com
> <mailto:g.rodola at gmail.com>> wrote:
> Extra: an argument in favor of using tempfile.mkdtemp() instead of
> TESTFN is parallel testing, but I think we're not using it.
> With -j you can do parallel testing and I know I always run with that
> on. But TESTFN does /attempt /to account for that
> by using the PID in the name.
> Having said that, I do use tempfile like Eric, Ronald, and Tim when I
> write tests as I have real-world experience using tempfile so I usually
> remember to clean up versus TESTFN which is Python stdlib internals only
> and I have to remember that it won't clean up itself.
I spend a decent amount of time rewriting tests to use TESTFN, since
that enables us to keep all test files constrained to either a default
directory or the one specified by --tempdir (which is a relatively
recent addition, I'll grant, but it's been useful for improving test
performance and stability when the default TEMP locations are not
reliable - e.g. if $tmp is a mount point it breaks some tests, if it's a
symlink it breaks others, if it's got particular permissions it breaks
others again, etc.).
That said, I'd love to have a context manager that we can use to make
this easier. Really, none of us should be having to decide "how am I
going to use a temporary location on the file system in my test",
because we should have one obvious (and easy!) way to do it.
But please, don't keep reinventing the functions we already have in
test.support for doing this (unless you're putting better versions in
More information about the Python-Dev