Repository navigation
Conversation
…irectory The histogram and KML tests, the Kennedy background maps and both rejection sampler test files wrote into whatever directory pytest ran from, and the sampler tests removed their files only if every assertion passed. They now write into tmp_path. Where os.remove would have failed on a missing output, the test now checks that the output exists. The set_inputs_log and set_outputs_log tests find the example logs through Path(__file__) instead of a path relative to the working directory; the monte_carlo_calisto fixture they use still needs the repository root. The sampler opens its logs "r+", so its integration test reads copies in tmp_path, which also lets it run on a read-only checkout. With nothing left for it to clean, _post_test_file_cleanup is gone along with the try/finally blocks that called it. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1253 +/- ##
========================================
Coverage 87.03% 87.03%
========================================
Files 130 130
Lines 18098 18098
========================================
Hits 15752 15752
Misses 2346 2346 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
thc1006
force-pushed
the
tst/monte-carlo-tests-leave-the-working-directory-alone
branch
from
December 3, 2026 03:53
e6cfcbf to
4c5b6b5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The follow-up mentioned in #1197, for the pre-existing problems pointed out in its review. Related to #1189.
Pull request type
Checklist
ruff check/ruff format --check,pylint) has passed locally--runslowon the four changed files (below)CHANGELOG.md: test-only, so no entry.Current behavior
plots.alland the KML export intest_monte_carlo.py, the Kennedy background maps, and bothtest_multivariate_rejection_sampler.pyfiles write into the directory pytest was started from. The sampler tests delete their files withos.removeat the end, so a test that fails before that line leaves them behind. Ondevelop, with anassert Falseadded after the lastmrs.sample(...)in the unittest_mrs_sample:test_monte_carlo_set_inputs_log,test_monte_carlo_set_outputs_logandtest_mrs_sample_integrationreadtests/fixtures/monte_carlo/example.*by a relative path. The sampler opens both files"r+", so with them read-onlytest_mrs_sample_integrationfails three times withPermissionError.New behavior
All of these now write into
tmp_path. With nothing left to clean up,_post_test_file_cleanupand thetry/finallyblocks are gone. Where a finalos.removealso caught a missing sampler output, the test now asserts the file exists, and the KML test gained the same check.The sampler integration test reads copies made with
shutil.copyfileintmp_path, as the pre-loaded fixture does since #1197. It passes with the tracked logs read-only, and also when pytest is started outside the repository root, where it fails three times withFileNotFoundErrorondevelop. The two log tests resolve the example logs fromPath(__file__), but they still need the root:monte_carlo_calistoloadsdata/...by relative paths.With the same forced failure on this branch,
git statusshows nothing new.Breaking change
Additional information
The rest of the suite also has to run from the repository root, for the same reason as the log tests. Some tests outside Monte Carlo,
test_sensor.pyandtest_encoding.pyamong them, still write into the working directory. Neither is in scope here.Pointing an output back at the working directory fails a named test: both
plots.allsaves, the KML, all five Kennedy cases, all three sampler integration cases andtest_mrs_sample. Putting four other changes back as they are ondevelopfails nothing. Two only matter outside the root or on a read-only checkout: the relative example paths, and the sampler reading the tracked logs. The other two are the scratch input prefixes intest_mrs_initializationandtest_mrs_sample; those files belong to the tests themselves, and a revert would leave them in the working directory again.Verified on
4c5b6b52, Python 3.10 and 3.14: