Fix mctest TypeError on re-runs: displaytime never restored from JSON - #2624
Merged
willend merged 1 commit intoSep 3, 2026
Merged
Conversation
mctest aborts a whole test run with
TypeError: %d format: a real number is required, not NoneType
in the "Display OK/FAILED" status line whenever it re-enters an
instrument test dir that already contains results from an earlier run.
Reported by users on PR mccode-dev#2622 (crash at the "Display FAILED" line).
How it happens:
- If the per-instrument test dir already exists - e.g. a re-run with
the same --testdir and --uid, which is exactly how the CI workflows
invoke mctest - shutil.copytree fails and mctest falls back to
InstrExampleTest.load() to rebuild the test objects from the JSON
files saved by the previous run.
- load() restored every stored field except "displaytime", leaving the
test object with displayed=<saved value> but displaytime=None. The
"binary already exists" branch of the compile loop skips the
mcdisplay step as well, so displaytime is never (re)measured.
- The run/status loop then formats test.displaytime with %d, which
raises TypeError and kills the run before any results are written.
The "Display FAILED" variant (the one seen on PR mccode-dev#2622) occurs when
the first run recorded displayed=false, e.g. because mcdisplay hit the
60 s --displaymax timeout - seen for MCPL instruments such as
ESS_BEER_MCPL / ESS_KVASIR / ESS_butterfly_MCPL_test.
Recreate the error (before this fix):
mctest --testdir tmp --instr ESS_KVASIR -n 1e4 --uid reproA
# 1st run: SUCCESS, saves results JSON
mctest --testdir tmp --instr ESS_KVASIR -n 1e4 --uid reproA
# 2nd run: "WARNING: Skipped ESS_KVASIR test - did ... exist
# already??" followed by the TypeError traceback above
The FAILED-branch variant is forced by making the display time out in
the first run, e.g. adding --displaymax 0.
Fix:
- InstrExampleTest.load() now restores displaytime from the saved JSON
(via obj.get, so JSON files written without the key still load).
- The Display OK/FAILED status lines fall back to 0 s when displaytime
is None, which also covers a binary present without saved display
time (e.g. a first run interrupted between compile and saving).
Verified: both re-run scenarios above now complete with SUCCESS, and
fresh mctest runs are unaffected.
5 tasks
willend
approved these changes
Sep 3, 2026
willend
left a comment
Contributor
There was a problem hiding this comment.
Argh, dumb detail. Thanks for the PR, let's just get it merged....
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.
Free-form text area
Please describe what your PR is adding in terms of features or bugfixes:
mctest aborts a whole test run with
in the "Display OK/FAILED" status line whenever it re-enters an instrument test dir that already contains results from an earlier run. Reported by users on PR #2622 (crash at the "Display FAILED" line).
How it happens:
Recreate the error (before this fix):
mctest --testdir tmp --instr ESS_KVASIR -n 1e4 --uid reproA
# 1st run: SUCCESS, saves results JSON
mctest --testdir tmp --instr ESS_KVASIR -n 1e4 --uid reproA
# 2nd run: "WARNING: Skipped ESS_KVASIR test - did ... exist
# already??" followed by the TypeError traceback above
The FAILED-branch variant is forced by making the display time out in the first run, e.g. adding --displaymax 0.
Fix:
Verified: both re-run scenarios above now complete with SUCCESS, and fresh mctest runs are unaffected.
Note: get('displaytime') used as it won't fail if the field is absent on an old test.
Declaration of use of AI-tools
Development OS / boundary conditions
Please describe what OS you developed and tested your additions on, and if any special dependencies are required:
OS X 14.6.1 (23G93)
PR Checklist for contributing to McStas/McXtrace
My work touches the code-generator in mccode/src
My work touches / adds to the runtime lib code (.c,.h etc in multiple locations
My PR is meant to fix a specific, existing issue
My contribution contains something else