oncoray / mirp

Medical Image Radiomics Processor
https://oncoray.github.io/mirp/
European Union Public License 1.2
51 stars 14 forks source link

Implement tmp_path #74

Closed Matthew-Jennings closed 6 months ago

Matthew-Jennings commented 6 months ago

Hi @alexzwanenburg,

I was just trying to run through the your test suite using pytest-xdist to accelerate the tests by distributing them over multiple processes. I noticed that you were manually creating and trying to handle cleanup of temporary test directories. This doesn't work well with multiprocessing, since some tests were using the same manually-created test dirs and running into PermissionErrors when trying to delete temp files that were being accessed by another process.

PyTest includes a wonderful temporary directory feature when setup and cleanup are neatly handled in the background. A big plus is that they play nicely with pydist-xdist - no PermissionErrors.

I've taken the liberty of implementing PyTest's tmp_path into your test suite, replacing the manual system.

If you do adopt the changes, I'd recommend merging this before merging #70 and adapting #70 to these changes along with the changes I proposed in my PR review.

Note that using pytest-xdist with n=14 brought the total test suite runtime down from 20:12 to 03:35!

To use it yourself, all you need to do is run:

pip install pytest-xdist
pytest -n <numprocesses>....<other pytest options> (e.g. pytest -n 14 -v --color=yes)