Skip to content

Warn for non-repeatable random tests in a testing environment#384

Merged
jcapriot merged 2 commits intosimpeg:mainfrom
jcapriot:random_warnings
Nov 5, 2024
Merged

Warn for non-repeatable random tests in a testing environment#384
jcapriot merged 2 commits intosimpeg:mainfrom
jcapriot:random_warnings

Conversation

@jcapriot
Copy link
Member

@jcapriot jcapriot commented Oct 30, 2024

When someone runs a test that would randomly initialize a random number generator from pytest or nosetest, issue a warning recommending setting the seed for repeatable tests.

This checks by using stack inspection looking for either _pytest. or nose.

@codecov
Copy link

codecov bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.

Project coverage is 86.19%. Comparing base (636e3ff) to head (58ff79e).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
discretize/tests.py 93.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #384      +/-   ##
==========================================
+ Coverage   86.17%   86.19%   +0.01%     
==========================================
  Files          90       90              
  Lines       18576    18603      +27     
  Branches     2099     2103       +4     
==========================================
+ Hits        16008    16034      +26     
  Misses       1884     1884              
- Partials      684      685       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jcapriot jcapriot requested a review from santisoler October 30, 2024 17:37
@jcapriot
Copy link
Member Author

@santisoler Thought this would be a good thing to do. It will only issue a warning when ran in the testing environment.

@jcapriot jcapriot merged commit 93d48ec into simpeg:main Nov 5, 2024
@jcapriot jcapriot deleted the random_warnings branch November 5, 2024 05:33
@santisoler
Copy link
Member

I like it! Nicely done.

prisae added a commit that referenced this pull request Jan 10, 2025
#384 popped up as warning in my tests, where is saw the missing white spaces ("berepeatable" and "isnot"):
```
  /home/dtr/Codes/emg3d/tests/test_simulations.py:959: UserWarning: You are running a pytest without setting a random seed, the results might not berepeatable. For repeatable tests please pass an argument to `random seed` that isnot `None`.
    discretize.tests.assert_isadjoint(
```
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