Skip to content
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

Store test-suite temporary files in temporary directories #422

Merged
merged 1 commit into from
Sep 20, 2022

Conversation

bemoody
Copy link
Collaborator

@bemoody bemoody commented Sep 20, 2022

When writing files as part of test cases, write them to a temporary
directory (created in setUpClass and destroyed in tearDownClass)
rather than writing them to the current working directory.

This allows running tests without modifying the working tree. It
enables running tests in parallel using pytest-xdist, which allows
running the whole test suite in around 12 seconds rather than 35
seconds.

It's also just cleaner not to dump a lot of temporary files in the
working tree.

It does feel weird to be creating and deleting temporary directories
in class methods, but it seems to work. (The alternative, using
setUp and tearDown, would mean creating a new directory for each
individual test function.)

When writing files as part of test cases, write them to a temporary
directory (created in setUpClass and destroyed in tearDownClass)
rather than writing them to the current working directory.

This allows running tests without modifying the working tree, which
means multiple test processes can run simultaneously from the same
working tree (e.g., using pytest-xdist).
@tompollard
Copy link
Member

Looks great. tempfile is new to me. Good to know!

@tompollard tompollard merged commit 3047c17 into main Sep 20, 2022
@tompollard tompollard deleted the tests-tmpdir branch September 20, 2022 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants