Skip to content

Conversation

@Utkarshkarki
Copy link

Migrate from seeded_test fixture to modern numpy Generator API

Replaces the legacy seeded_test fixture using np.random.seed() with a modern rng fixture using np.random.default_rng(). This eliminates global state pollution and enables thread-safe random number generation.

Changes:

  • Replaced seeded_test with rng fixture in conftest.py
  • Migrated 30+ tests across 6 files
  • Updated all np.random.xxx() calls to rng.xxx() using Generator API

Benefits:

  • No global state pollution
  • Thread-safe parallel testing
  • Modern numpy best practices
  • Maintains reproducibility (same seed)

Closes #8035

@pytest.fixture(scope="function", autouse=False)
def seeded_test():
np.random.seed(20160911)
@pytest.fixture(scope="function")
Copy link
Member

Choose a reason for hiding this comment

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

I rather move away from magic fixtures, just let each test create its own rng, it's not that much extra code

Copy link
Author

Choose a reason for hiding this comment

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

Okay, I will make required changes

Copy link
Author

Choose a reason for hiding this comment

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

Please check the changes

Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

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

Looks great!

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.47%. Comparing base (056e80c) to head (3a2131b).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8037      +/-   ##
==========================================
+ Coverage   91.44%   91.47%   +0.02%     
==========================================
  Files         116      116              
  Lines       19002    19065      +63     
==========================================
+ Hits        17377    17440      +63     
  Misses       1625     1625              

see 12 files with indirect coverage changes

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

@ricardoV94
Copy link
Member

For last commit I prefer the more strict old test that no draws are close. Can you use a different seed and revert to the old check?

@Utkarshkarki
Copy link
Author

I will look into it.

@Utkarshkarki
Copy link
Author

Thanks for the suggestion!
I reverted to the original strict np.any(np.isclose(...)) checks and updated the random seeds.
I ran the affected AR, GARCH11, and Euler–Maruyama batched-size tests locally and they all pass.
I didn’t run the full test_timeseries.py file since it includes long MCMC tests that are very slow on Windows.

@ricardoV94
Copy link
Member

need to run pre-commit

Copy link
Author

@Utkarshkarki Utkarshkarki left a comment

Choose a reason for hiding this comment

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

yes i will do it

Copy link
Author

@Utkarshkarki Utkarshkarki left a comment

Choose a reason for hiding this comment

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

I think all the changes are perfect now, and I have reviewed them. Please tell if any more changes are nedded.

Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

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

3 tests still have a changed condition that is less strict than before

@Utkarshkarki
Copy link
Author

Please, can you review the changes once

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.

Get rid of seeded_test fixture

2 participants