-
Notifications
You must be signed in to change notification settings - Fork 102
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
How to update snapshots with unittest? #51
Comments
Not sure if there is a way to do this, though if there is I'd welcome a PR to add it to the documentation. |
I don't believe You could implement it yourself by setting if __name__ == "__main__":
import snapshottest.unittest
import sys
argv = sys.argv
if "--update-snapshot" in argv:
snapshottest.unittest.TestCase.snapshot_should_update = True
argv = argv.copy() # (don't modify sys.argv itself)
argv.remove("--update-snapshot")
unittest.main(argv=argv) It might make sense to add a new |
An alternative could be to set it in an environment variable. What do you think about that approach? |
I'm of mixed opinions on using an environment variable to request snapshot updates:
I think I'd lean toward providing the Of course, the other way to achieve this is deleting your existing snapshot files and re-running the tests, which will generate new snapshots. Maybe just document that for unittest? |
Ah, I see, that's going away in #73. So I guess this does need to get addressed some other way, or it'll be really hard for unittest users to get started with snapshots. |
I added an environment variable option to #112 so that it doesn't make things worse for unittest users. I think it would be better if someone who uses and understands unittest added a |
I'm much more familiar with Django's unittest wrapper (which has its own test runner and command-line handling), but could take a shot at a Just realized that raw unittest is probably also missing the end-of-test-session handling (delete unvisited snapshots and report summary), which are coded separately for each of the other three test frameworks. |
Add test-session-level features for raw unittest framework: * Support --snapshot-update command line option * Issue "SnapshotTest summary" at end of test run * Remove unused snapshots when in update mode This also adds snapshottest-augmented versions of the various ways to run unittest: * `python -m snapshottest ...` parallels `python -m unittest ...` (via module-level `__main__.py`). * `snapshottest.main()` wraps `unittest.main()`. * `SnapshotTestRunnerMixin` can be used with other unittest TestRunner classes. Closes syrusakbary#51
Add test-session-level features for raw unittest framework: * Support --snapshot-update command line option * Issue "SnapshotTest summary" at end of test run * Remove unused snapshots when in update mode This also adds snapshottest-augmented versions of the various ways to run unittest: * `python -m snapshottest ...` parallels `python -m unittest ...` (via module-level `__main__.py`). * `snapshottest.main()` wraps `unittest.main()`. * `SnapshotTestRunnerMixin` can be used with other unittest TestRunner classes. Closes syrusakbary#51
Appending
--update-snapshot
as is done with nosetest, etc throwsImportError: No module named --update-snapshot
. The docs are unclear how exactly to pass this param when using unittest. Is this features supported when usingunittest
?The text was updated successfully, but these errors were encountered: