Skip to content

pytest and TMPDIR housekeeping #6036

@pavoljuhas

Description

@pavoljuhas

pytest leaves behind a LOT of temporary files

After executing all cirq unit tests with pytest the root temporary directory contains 31 leftover files and 38 leftover directories taking about 30G of disk space in total. The majority of that is taken by /tmp/cirq-pytest which has 59 virtual environments - 3 base environments and 56 per each isolated notebook test.

Some ideas how to reduce disk usage in isolated_notebook_test

  • instead of creating new venv-s for each notebook, use one base environment with "PIP_TARGET" and "PYTHONPATH" pointing to a temporary directory (similar as in Prevent notebook tests from changing the pytest Python environment #6032). pip install commands run in the notebook should then keep their base environment unchanged.
  • alternatively, instead of cloning a new venv for each tested notebook, create an rsync backup of the initial base venv and restore the base with rsync -a --delete base-backup/ base/ before each test. This would probably need several base environments for each parallel pytest worker.
  • make sure all tests clean up their temporaries after successful completion

Here is how I checked for the leftover files (docker tests are not set up on my workstation).
Note: my work tree had a change in the isolated_notebook_test.py which makes it execute all isolated notebook tests.

$ touch t0; check/pytest -m 'slow or not slow' -k 'not docker'; touch t1
$ find /tmp -maxdepth 1 -user $USER -newer t0 -not -newer t1

Cirq version

1.2.0.dev at 8b97aa5

Metadata

Metadata

Assignees

Labels

good first issueThis issue can be resolved by someone who is not familiar with the codebase. A good starting issue.kind/healthFor CI/testing/release process/refactoring/technical debt itemsno QC knowledge neededWant to contribute to Cirq, but don't know quantum computing? This issue is for you.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions