Skip to content

TST: keep the Monte Carlo fixtures out of the working directory - #1197

Open
thc1006 wants to merge 1 commit into
RocketPy-Team:developfrom
thc1006:tst/monte-carlo-fixtures-write-to-tmp-path
Open

thc1006 wants to merge 1 commit into
RocketPy-Team:developfrom
thc1006:tst/monte-carlo-fixtures-write-to-tmp-path

Conversation

@thc1006

@thc1006 thc1006 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Running the unit tests leaves three zero-byte logs in the repository root, and nothing ignores them. Addresses #1189.

Pull request type

  • Code maintenance (refactoring, formatting, tests)

Checklist

  • Tests for the changes have been added (if needed)
  • Docs have been reviewed and added / updated
  • Lint (ruff check / ruff format --check) has passed locally
  • All tests have passed locally
  • CHANGELOG.md: nothing user-facing changes here, so no entry.

Current behavior

The two shared Monte Carlo fixtures pass a bare filename="monte_carlo_test", which resolves against whatever directory pytest was started from:

$ git status --porcelain          # nothing
$ pytest tests/unit/simulation -q
$ git status --porcelain
?? monte_carlo_test.errors.txt
?? monte_carlo_test.inputs.txt
?? monte_carlo_test.outputs.txt

test_ellipses_background_saves_file_successfully writes a fourth into the same place and removes it in a finally, which does not run if the process is killed.

New behavior

All three take tmp_path, so the logs go where pytest already cleans up after itself, and the plot test needs no cleanup clause.

A test asserts it, on filename rather than on the three file attributes: import_results repoints those at whatever it read, so they are not what the fixtures control. Putting the bare name back turns it red for both fixtures.

Breaking change

  • No

Test-only.

Additional information

One thing I found while writing the assertion, and fixed with it. monte_carlo_calisto_pre_loaded also reads its example file by a path relative to the working directory. import_outputs opens that path "r+", and "w+" when it is missing, so the read target is a tracked file opened for writing and a wrong guess would create one inside the tree. It is resolved against the fixture module now. Nothing was being created today, since the file it names does exist; this is the same defect as the one above rather than a new symptom.

What this does not cover, so it is not mistaken for covered. tests/integration/simulation/test_monte_carlo.py writes four more files into the working directory, a .kml and three .png, and asserts on them by bare name. Those differ from the case above in that the tests do remove them, through _post_test_file_cleanup in a finally. The gap there is narrower: a finally does not run if the process is killed. Changing them means changing the assertions that name them, in a file this branch does not touch and whose tests are marked slow, so I have left them and am saying so rather than letting the issue look fully answered. The three log names in that cleanup list are inert after this change, and I have left those entries alone for the same reason.

While there: import_results(filename=...) hands the same name to import_outputs, import_inputs and import_errors, so after the pre-loaded fixture runs, all three attributes point at example.outputs.txt. I have left that alone, since it is the documented signature rather than anything this changes.

Verified on a50d07d5:

pytest tests/unit/simulation   333 passed, 7 skipped, 1 failed
  git status afterwards        clean
ruff check . / ruff format --check   clean

The one failure is test_ellipses_reports_an_image_path_that_does_not_exist, an imageio import this machine cannot satisfy. It is red on develop too.

Both shared fixtures passed a bare filename, which resolves against whatever
directory pytest was started from, so a unit run left three zero-byte logs in
the repository root with nothing ignoring them. They take tmp_path now, and so
does the background-plot test, which wrote a fourth there and removed it in a
finally that does not run if the process is killed.

The new test asserts it on filename rather than on the three file attributes.
import_results repoints those at whatever it read, so they say nothing about
where a run would write. Putting either bare name back turns it red.

monte_carlo_calisto_pre_loaded also read its example by a path relative to the
working directory, and import_outputs opens that path "r+", or "w+" when it is
missing. The read target is a tracked file opened for writing, and a wrong
guess would create one inside the tree. Resolved against the fixture module
now. Nothing was being created today, since the file it names does exist.

tests/unit/simulation: 333 passed, 7 skipped, and the one failure is the
imageio import that is red on develop too. The tree is clean afterwards, which
is what this is for. ruff and ruff format are clean.

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
@thc1006
thc1006 requested a review from a team as a code owner September 16, 2026 16:43
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.58%. Comparing base (a50d07d) to head (1bbaadf).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1197   +/-   ##
========================================
  Coverage    91.58%   91.58%           
========================================
  Files          132      132           
  Lines        18404    18404           
========================================
  Hits         16855    16855           
  Misses        1549     1549           

☔ 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.

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