Testing#
Testing the Template#
To ensure that your template is working, you can run the test.sh script.
The test.sh will do a run of the template, and then run the django tests and prospector against it.
$ test.sh keepenv
Note
If you do not pass the argument keepenv, it will delete the old virtualenvironment. If you want to do this, simply run:
$ test.sh
Testing/Validation within your Project#
This will be run automatically when you attempt to commit code but if you want to manually validate/fix your code syntax during development you can run:
$ poetry run pre-commit run --all-files
This project uses the pytest framework with pytest-django enabling Django tests and pytest-playwright for end-to-end testing. This replaces the default Django tests using unittest.
Django tests can be run by running:
$ ./manage.py test
Warning
When doing one of the following, be sure to build Vite assets before running tests:
Initializing the project manually
Adding a new Vite asset (see Additional Assets)
To build the assets run:
$ npm run build
If you don’t run this command before tests run, some tests may fail even if they would normally pass.
Pytest#
While pytest is backwards-compatible with unittest, there are some key differences that implementers need to understand. If you’re new to pytest in Django or playwright testing, reviewing the documentation for these libraries is well worth the time.
Playwright#
Playwright allows for robust frontend testing across browser engines
Of note is Playwright’s codegen feature, which allows you to perform actions in the browser and have Playwright generate the code to perform those actions automatically.
Rarely is codegen’s generated code production ready immediately after recording, but it will get you most of the way through your end-to-end testing.
Coverage.py can come in handy here in ensuring that the tests you write cover all of the code you write.