Skip to content

Remove assert statements to support Python -O / -OO#606

Open
arunkumargururaj07-star wants to merge 2 commits intobayesflow-org:mainfrom
arunkumargururaj07-star:main
Open

Remove assert statements to support Python -O / -OO#606
arunkumargururaj07-star wants to merge 2 commits intobayesflow-org:mainfrom
arunkumargururaj07-star:main

Conversation

@arunkumargururaj07-star
Copy link

This fixes test failures under Python’s optimization flags (-O / -OO).

I found that test_copy_unequal was silently passing under -O because the helper assert_layers_equal used assert statements — which get stripped when assertions are disabled.

This PR replaces all assert calls in tests/utils/assertions.py with explicit ValueError raises, so the tests behave consistently regardless of optimization level.

Also cleaned up a few commented-out assert lines for clarity.

@LarsKue LarsKue self-requested a review January 9, 2026 12:04
Copy link
Contributor

@LarsKue LarsKue left a comment

Choose a reason for hiding this comment

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

@arunkumargururaj07-star Thank you for the PR! Unfortunately, I think the changes you made are not fully in the spirit of the corresponding issue. Since we use pytest to run the tests, the best practice is to actually write the plain assert statements in the tests. The idea of the issue was to add a git workflow that runs the tests with the -O or -OO flag. pytest actually supports running the tests with these flags, since it automatically rewrites assert statements in the test directory at import time (i.e., before they are stripped from the optimization). assert statements in the main codebase will still be stripped, as expected.

I'm sorry if this was not clear from the issue I made. Would you be able to change this PR or (probably cleaner) open a new one that does not change the tests themselves, but rather the git workflows?

@arunkumargururaj07-star
Copy link
Author

@LarsKue Thanks for the clarification. I’ve opened this new PR which only updates the CI workflow to run tests under -O / -OO, without modifying any test code.

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.

2 participants