syrusakbary / snapshottest

Snapshot Testing utils for Python 📸
MIT License
525 stars 102 forks source link

Snapshots don't update when running nosetests with a class name #153

Open brettdh opened 3 years ago

brettdh commented 3 years ago

When running nosetests with a test class name, snapshots are not updated when --snapshot-update is provided on the command line:

# this works
$ nosetests --snapshot-update path/to/test_file.py

# this doesn't
$ nosetests --snapshot-update path/to/test_file.py:TestClass

Minimal repro project here: https://github.com/brettdh/demo-snapshottest-update-bug

brettdh commented 3 years ago

From my investigation, the problem appears to be that wantClass is not called if only a class is specified on the nosetests command line. This seems a bit odd, but perhaps it's because the user's command overrides what the plugins say.

For my use case, it might be sufficient to also override wantMethod and look up the class from the method, and set the snapshot_should_update class variable there - but perhaps the snapshot_should_update flag should be set and looked up in a more global context than individual test classes? Even if I take the wantMethod approach, I expect wantMethod won't be called if I specify a specific method on the command line.