This guide explains how to run tests for the Screenshot to Code project.
The backend uses pytest for testing. All tests are located in the backend/tests directory.
Make sure you have Poetry installed and have installed all dependencies:
cd backend
poetry installcd backend
poetry run pytestpoetry run pytest -vvpoetry run pytest tests/test_screenshot.pypoetry run pytest tests/test_screenshot.py::TestNormalizeUrlpoetry run pytest tests/test_screenshot.py::TestNormalizeUrl::test_url_without_protocolpoetry run pytest --cov=routespoetry install --with dev pytest-xdist # Install if not already installed
poetry run pytest -n autoThe pytest configuration is defined in backend/pytest.ini:
- Tests are discovered in the
testsdirectory - Test files must match the pattern
test_*.py - Test classes must start with
Test - Test functions must start with
test_ - Verbose output and short traceback format are enabled by default
- Create a new test file in
backend/tests/following the naming conventiontest_<module>.py - Import the functions/classes you want to test
- Write test functions or classes following pytest conventions
Example:
import pytest
from routes.screenshot import normalize_url
def test_url_normalization():
assert normalize_url("example.com") == "https://example.com"