Skip to content

TST: keep the remaining Monte Carlo test outputs out of the working directory - #1253

Open
thc1006 wants to merge 1 commit into
RocketPy-Team:developfrom
thc1006:tst/monte-carlo-tests-leave-the-working-directory-alone
Open

thc1006 wants to merge 1 commit into
RocketPy-Team:developfrom
thc1006:tst/monte-carlo-tests-leave-the-working-directory-alone

Conversation

@thc1006

@thc1006 thc1006 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

The follow-up mentioned in #1197, for the pre-existing problems pointed out in its review. Related to #1189.

Pull request type

  • Code maintenance (refactoring, formatting, tests)

Checklist

  • Lint (ruff check / ruff format --check, pylint) has passed locally
  • Tests have passed locally, with --runslow on the four changed files (below)
  • CHANGELOG.md: test-only, so no entry.

Current behavior

plots.all and the KML export in test_monte_carlo.py, the Kennedy background maps, and both test_multivariate_rejection_sampler.py files write into the directory pytest was started from. The sampler tests delete their files with os.remove at the end, so a test that fails before that line leaves them behind. On develop, with an assert False added after the last mrs.sample(...) in the unit test_mrs_sample:

$ git status --porcelain | grep '^??'
?? mrs.errors.txt
?? mrs.inputs.txt
?? mrs.outputs.txt
?? valid_mc.inputs.txt
?? valid_mc.outputs.txt

test_monte_carlo_set_inputs_log, test_monte_carlo_set_outputs_log and test_mrs_sample_integration read tests/fixtures/monte_carlo/example.* by a relative path. The sampler opens both files "r+", so with them read-only test_mrs_sample_integration fails three times with PermissionError.

New behavior

All of these now write into tmp_path. With nothing left to clean up, _post_test_file_cleanup and the try/finally blocks are gone. Where a final os.remove also 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.copyfile in tmp_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 with FileNotFoundError on develop. The two log tests resolve the example logs from Path(__file__), but they still need the root: monte_carlo_calisto loads data/... by relative paths.

With the same forced failure on this branch, git status shows nothing new.

Breaking change

  • No

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.py and test_encoding.py among 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.all saves, the KML, all five Kennedy cases, all three sampler integration cases and test_mrs_sample. Putting four other changes back as they are on develop fails 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 in test_mrs_initialization and test_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:

pytest tests/unit                  2649 passed, 24 skipped
pytest tests/integration           180 passed, 38 skipped (3 PyVista animation tests deselected)
pytest tests/acceptance            18 passed
four changed files, --runslow      21 passed
  git status afterwards            clean
ruff check . / ruff format --check .  clean
pylint rocketpy/ tests/ docs/      exit 0

@thc1006
thc1006 requested a review from a team as a code owner December 3, 2026 01:22
…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

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.03%. Comparing base (d3cf83a) to head (4c5b6b5).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thc1006
thc1006 force-pushed the tst/monte-carlo-tests-leave-the-working-directory-alone branch from e6cfcbf to 4c5b6b5 Compare December 3, 2026 03:53
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.

1 participant