PyMC provides testing utilities to speed up test suites by mocking MCMC sampling with prior predictive sampling. This is useful for checking model structure without running expensive inference.
| Speed | Fast (seconds) | Slow (minutes) | | Use case | Model structure, downstream code | Posterior values, convergence | | Output | prior, priorpredictive | Full posterior, samplestats, warmup groups | | Divergences | Mocked (configurable) | Real diagnostics |
Use mocking when: Testing model specification, CI/CD pipelines, plotting code, API integration, serialization.
Testing PyMC models with pytest. Use when writing unit tests for Bayesian models, setting up test fixtures, mocking MCMC sampling, or testing model structure. Covers pymc.testing.mock_sample, pytest fixtures, and the distinction between fast structure-only tests (mocking) and slow posterior inference tests. Triggers on: testing PyMC, pytest, unit tests for models, mock sampling, test fixtures, CI/CD for Bayesian models. Source: pymc-labs/python-analytics-skills.