3 ms·
This. Simple, well documented, works for 99% of test cases. It's also how Django does it [0]. True, it has some warts, and you need to learn about e.g. `autosp
by guitarbill 9y ago
This. Simple, well documented, works for 99% of test cases. It's also how Django does it [0].
True, it has some warts, and you need to learn about e.g. `autospec`. But for better or worse, it's the "standard" way, and for me that low barrier to entry/universality is a bigger value-add than `assert` vs `self.assertEqual`, etc.
[0] https://docs.djangoproject.com/en/1.11/topics/testing/ https://docs.djangoproject.com/en/1.11/topics/testing/
- orf 9y agoDjango has some different constraints than most projects, and the test suite has been around for a long long time. In most situations pyest is a superior choice that goes beyond 'assert' Vs 'self.assert*'.
- sidlls 9y agoHow is pytest superior?
- orf 9y agoIt's much more pythonic for starters, java-style camelcase is not great to look at. Fixtures are very powerful, as are parameterized tests. Assertion failures give you a lot of output to help you debug, like local variables and their values. There are a wide variety of plugins to help you test various frameworks (pytest-django, pytest-asyncio), various other plugins that plug into linters (pytest-flake8, pytest-isort). Super easy parallel tests. If you need to write something that has as few (or no) external dependencies then the standard unittest library is OK. All in all it's a bit like using urllib over requests. Sure, both work and get the job done, but one is just nicer.