Testing and Coverage
Pytest
We use pytest as our test runner.
It also supports Django unittest classes
You can check tests code in django_app/tests
# run tests
$ pytest django_app/tests/unittest --numprocesses 2
Tests Structure
django_app
├── conftest.py
├── tests
│ ├── integration # contains integration tests
│ └── unittest # contains unit tests
Integration Tests
Even you can use The test client to make sure the Django view works as expected, it can not promise the Javascript can work with Django without issue.
That is why we need Integration Tests in some cases.
In Django community, people usually choose selenium, but in SaaS Hammer, I recommend people to use Playwright instead.
Notes:
Playwrightis very fast, and supports multiple programming languages.Playwrightalso supportsparallel testing, which means, we can launchparallel testingin the CI for shorter execution time.Playwrighthas clean API, strong team and active community.SaaS Hammeralready import and configPlaywrightas our integration testing solution.
Coverage
We use pytest-cov to help us collect coverage data and generate coverage report.