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

Racey import/export tests with pytest-xdist #922

Open
hcsch opened this issue Mar 1, 2025 · 2 comments
Open

Racey import/export tests with pytest-xdist #922

hcsch opened this issue Mar 1, 2025 · 2 comments
Labels
question Further information is requested

Comments

@hcsch
Copy link

hcsch commented Mar 1, 2025

Because pytest-xdist is listed in the pyproject.toml I used pytest with xdist. This however leads to some tests like e.g. TestMeshProperties.test_properties in test_mesher.py failing depending on the execution timing of the tests and what other tests are running in parallel. This is because multiple tests are racing to write/read from the same file.

These issues can be avoided by using a tempdir/tempfile per test, instead of a fixed file name in the working directory like e.g. test.3mf. pytest has a fixture for that (tmp_path), however I wasn't able to get that to work within the unittest.TestCase classes. If you'd like I can open a PR which adds a TmpPathTestCase to the affected test files, which sets self.tmp_path to a temporary directory specific to each test that gets cleaned-up afterwards. If you want to generally restructure tests more towards pytest, using the tmp_path fixture would probably be cleaner in the long run though.

@gumyr
Copy link
Owner

gumyr commented Mar 6, 2025

I think you must have noticed this problem during the short window that this new xdist functionality was being introduced as your suggestions have already been implemented in the tests. Please take a look and let me know if you still think there are issues with any of the tests.

@hcsch
Copy link
Author

hcsch commented Mar 7, 2025

Ah, sorry in that case. I should have had a closer look at the dev branch as well and not just the latest release (0.9.1) that I was packaging in nix. I'll try building a newer version some time soon and will close the issue when I've confirmed that this has been resolved already :)

@gumyr gumyr added the question Further information is requested label Mar 8, 2025
@gumyr gumyr added this to the Not Gating Release 1.0.0 milestone Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants