Skip to content

Add test cleanup fixtures and remove global state#42

Open
bjarketol wants to merge 4 commits intoEUFLOW:mainfrom
bjarketol:fix-tests-cleanup
Open

Add test cleanup fixtures and remove global state#42
bjarketol wants to merge 4 commits intoEUFLOW:mainfrom
bjarketol:fix-tests-cleanup

Conversation

@bjarketol
Copy link
Contributor

@bjarketol bjarketol commented Jan 20, 2026

Summary

Closes #41

  • Add pytest fixtures for automatic test cleanup
  • Mark slow tests (wayve) with @pytest.mark.slow

Problem

Tests were leaving behind output directories (output_pywake_4wts/, output_test_foxes/, etc.) that accumulated over multiple runs.

Solution

Created tests/conftest.py with:

  • Pre-cleanup fixture - Removes leftover output directories at session start
  • output_dir fixture - Provides unique temp directory per test, cleans up on success, preserves on failure
  • Failure tracking - Uses pytest hooks to detect failures and conditionally preserve output for debugging

Changes

File Change
tests/conftest.py New file with cleanup fixtures
tests/test_foxes.py Use fixtures
tests/test_pywake.py Use output_dir fixture
tests/test_cs.py Use output_dir fixture
tests/test_wayve.py Use output_dir fixture, add slow marker

Test plan

  • Run uv run python -m pytest tests/ -m "not slow" - all 33 tests pass
  • Verify no output_* directories remain after test run

@bjarketol
Copy link
Contributor Author

@SchmJo can you review this? or what is the process?

@SchmJo
Copy link
Contributor

SchmJo commented Jan 22, 2026

I am not entirely sure why you are introducing conftest.py, which looks like a complication. Was the testing not running fine originally? Usually tests run as part of CI/CD , ie., github actions, and the leftover folders don't matter. That being said, I am of course happy with cleaning up after tests.

I also don't understand your special treatment of foxes engines, they should not matter for tests. My feeling is that I am missing something. Also, I do not feel comfortable reviewing the pywake part, I guess you need to catch Julian for this. The foxes part I can do, once I understand the main idea!

@bjarketol
Copy link
Contributor Author

@SchmJo The main goals are:

  • Avoid many folders on testing by letting tests perform a clean-up after tests pass
  • Mark very slow tests, to optionally skip those for faster iteration cycles

I am happy to skip the foxes engine resetting, that was a minor thing.

@bjarketol
Copy link
Contributor Author

@SchmJo I removed the foxes engine resetting and the engine argument to the tests.

Can you see if you are happy with the rest?

@bjarketol
Copy link
Contributor Author

bjarketol commented Jan 22, 2026

@kilojoules can you review the pywake part?

Copy link
Contributor

@SchmJo SchmJo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on WIFA, I am still not sure why you are so interested in the tests - are they relevant for your own workflow?

@bjarketol
Copy link
Contributor Author

@SchmJo @kilojoules can you take a look at this again?

If you prefer the old style of having explicit folders, let me know, then perhaps I can just add a cleaning step to each test instead?

Copy link
Contributor

@SchmJo SchmJo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The foxes part looks fine for me

@mathieu7an
Copy link
Contributor

I am fine with the modifications. Should we merge this branch?

Copy link
Member

@kilojoules kilojoules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me beyond the numpy 2 thing

@bjarketol bjarketol force-pushed the fix-tests-cleanup branch 4 times, most recently from 69637af to 752168a Compare February 25, 2026 09:24
- Add test cleanup fixtures and output_dir management (conftest.py)
- Simplify foxes engine handling and fix test compatibility
- Split run_pywake into focused helper functions
- Add foxes turbine-based data test with density support
- Fix wayve test performance (510s to 6s)
- Pin numpy<2.0 for wayve compatibility (np.trapz removal)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
 * Skip floris tests for unsupported python versions
@bjarketol bjarketol requested a review from kilojoules February 25, 2026 10:09
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.

Tests do not clean up after themselves

4 participants