[Python-Dev] Adding test.support.safe_rmpath()

Ronald Oussoren ronaldoussoren at mac.com
Thu Feb 14 04:46:43 EST 2019


—

Twitter: @ronaldoussoren
Blog: https://blog.ronaldoussoren.net/

> On 13 Feb 2019, at 16:10, Giampaolo Rodola' <g.rodola at gmail.com> wrote:
> 
> 
> 
> On Wed, Feb 13, 2019 at 2:27 PM Ronald Oussoren <ronaldoussoren at mac.com <mailto:ronaldoussoren at mac.com>> wrote:
> 
> 
>> On 13 Feb 2019, at 13:24, Giampaolo Rodola' <g.rodola at gmail.com <mailto:g.rodola at gmail.com>> wrote:
>> 
>> 
>> Hello,
>> after discovering os.makedirs() has no unit-tests (https://bugs.python.org/issue35982 <https://bugs.python.org/issue35982>) I was thinking about working on a PR to increase the test coverage of fs-related os.* functions. In order to do so I think it would be useful to add a convenience function to "just delete something if it exists", regardless if it's a file, directory, directory tree, etc., and include it into test.support module.
> 
> Something like shutil.rmtree() with ignore_errors=True?
> 
> shutil.rmtree() is about directories and can't be used against files. support.rmpath() would take a path (meaning anything) and try to remove it.

You’re right.  

I usually use shutil.rmtree for tests that need to create temporary files, and create a temporary directory for those files (that is, use tempfile.mkdtemp in setUp() and use shutil.rmtree in tearDown()). That way I don’t have to adjust house-keeping code when I make changes to test code.

Ronald

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20190214/46b9d666/attachment.html>


More information about the Python-Dev mailing list