This document is not written in any particular order. It is ordered in sections
- Tips for using the Selenium WebDriver
- Using the pytest command on the CLI
- Configurating Pytest for Django
Follow at your own risk!
- Make sure to use driver methods to see where you're at!
eg:
driver.page_source
tells you what page you're on! - Make sure test cases are proper - you can check if an element exists; and more!
In this section you'll find different ways you can use the pytest command on CLI; most notably i found these to be helpful. (http://doc.pytest.org/en/latest/usage.html)
pytest -v --cov
- this throws verbose and coverage
pytest -v --cov=<projectname>
this throws verbose and coverage for specific project
Otherwise, you can also set up configuration files - so you don't have to type in pytest with long flags each time.
PS: Not required for CA.
You'll need the two plugins for pytest
- pytest-django
- coverage.py plugin (is installed by default - I believe!)
Step 1. Create two files in the root of your project directory (./pytest.ini & ./.coveragerc)
Step 2. Configure the two files in the following manner:
pytest.ini (http://doc.pytest.org/en/latest/customize.html)
[pytest]
python_files = tests.py test_*.py *_tests.py
DJANGO_SETTINGS_MODULE = personal_portfolio.settings
addopts = --cov=. --cov-report html --cov-config=.coveragerc
.coveragerc (https://coverage.readthedocs.io/en/latest/config.html)
[run]
omit = */manage.py, */wsgi.py, */urls.py, */views.py, */forms.py
branch = true
source = .
[report]
show_missing = false
Most importantly, check that the two files are coupled with the --cov-config=.coveragerc flag.
Step 3. You can run pytest with just the pytest -v
now and it should run it with all the addopts.
- https://pytest-django.readthedocs.io/en/latest/database.html
- https://django-testing-docs.readthedocs.io/en/latest/views.html
- https://stackoverflow.com/questions/13202385/django-reverse-with-arguments-and-keyword-arguments-not-found
- https://docs.djangoproject.com/en/2.2/topics/testing/tools/
- https://pytest-django.readthedocs.io/en/latest/usage.html#basic-usage