DEV Community

Discussion on: Snapshot Testing in Python

Collapse
 
briwoto profile image
briwoto

Hi,
When using with pytest, there is a parameter named "snapshot" passed into every def. Where is that parameter coming from? The PyTest example does not contain any "import" commands

Collapse
 
leahein profile image
Leah Einhorn • Edited

Good question! This is part of the pytest "magic". The short answer is that if you install snapshottest, that parameter will automatically be available when you run your tests with pytest. There is no need to import or define anything else!

The longer answer is that pytest uses fixtures as function arguments; if you're not familiar with it and want to learn more, you can read the docs here.
It looks for fixtures in several locations (and so you don't need to import them), a common one being conftest.py. In the case of the snapshottest library, the fixture is defined here and configured so that pytest knows where to look for it.

Hope that helps!