Skip to content

Use mock sample in tests #489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

williambdean
Copy link
Contributor

@williambdean williambdean commented Jun 16, 2025

Saving about 50s in the test suite by mocking pm.sample


📚 Documentation preview 📚: https://causalpy--489.org.readthedocs.build/en/489/

Copy link

codecov bot commented Jun 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.59%. Comparing base (632c457) to head (c3b6423).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #489   +/-   ##
=======================================
  Coverage   94.59%   94.59%           
=======================================
  Files          28       28           
  Lines        2053     2053           
=======================================
  Hits         1942     1942           
  Misses        111      111           

☔ View full report in Codecov by Sentry.
📢 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.

@williambdean
Copy link
Contributor Author

66s -> 16s test suite runs. nice

@williambdean williambdean added the no releasenotes Skipped in automatic release note generation label Jun 16, 2025
@williambdean
Copy link
Contributor Author

Doing for doctest would be greater reduction of time

@williambdean
Copy link
Contributor Author

williambdean commented Jun 16, 2025

6m31s down to 1m58s

Copy link
Collaborator

@drbenvincent drbenvincent left a comment

Choose a reason for hiding this comment

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

This is pretty cool - thanks for the contribution.

On my local machine...

  • make test runs in 24 seconds (down from 50 seconds on main) ✅
  • make doctest speed is unchanged❓

I guess I just have some questions to make sure I understand this

  • mock_sample_for_doctest kind of looks transparent in that we're overriding pm.sample with pymc.testing.mock_sample. Though that's not working or doing much?
  • mock_pymc_sample is provided as an input to tests (like test_did for example) but it's never used anywhere in those test functions. So this is a bit confusing. Does this make the use of sample_kwargs irrelevant now?

@williambdean
Copy link
Contributor Author

Noticing that too. Weird thing is pytest --doctest-modules seems to work for me but pytest --doctest-modules causalpy/ does not

@williambdean
Copy link
Contributor Author

mock_pymc_sample is a fixture that doesn't have to be used directly in the test function since it replaces pm.sample but then puts back original at the end of the test. Just like many of those tests are not using pm.sample directly (i.e. fit method), the fixture doesn't have to be used directly.

@williambdean
Copy link
Contributor Author

williambdean commented Jun 29, 2025

So the pm.sample is being mocked in the CI/CD tests. We can see with the drop in the run times. Need to figure out why calling pytest --doctest-modules causalpy/ doesn't work when pytest --doctest-modules does. Is this a blocker for merging this PR?

EDIT: Figured out with 990104d. The conftest file was not being picked up based on the test structure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no releasenotes Skipped in automatic release note generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants