On Fri, Feb 15, 2019 at 11:44 AM Steve Dower <steve.do...@python.org> wrote:
> 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.

I found an old rejected issue [1] for adding a `tmpdir` method to
unittest.TestCase, which is actually a solution that we've
independently developed and use frequently for work.  It basically
works by registering a cleanup function before returning the path to
the temporary directory, so you just call `self.tmpdir()`, use the
path, forget about cleanup, and don't lose a level of indentation to a
context manager.  I think it would be worthwhile to reconsider this
addition to unittest, or add it as a standard base test class in
test.support (though either way it would need a cleaner and more
robust implementation than is offered in that issue).

[1] https://bugs.python.org/issue2156

-- 
Zach
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to