Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
Testing Guide
This guide explains how to run tests for the Screenshot to Code project.
Backend Tests
The backend uses pytest for testing. All tests are located in the backend/tests directory.
Prerequisites
Make sure you have Poetry installed and have installed all dependencies:
cd backend
poetry install
Running Tests
Run all tests
cd backend
poetry run pytest
Run tests with verbose output
poetry run pytest -vv
Run a specific test file
poetry run pytest tests/test_screenshot.py
Run a specific test class
poetry run pytest tests/test_screenshot.py::TestNormalizeUrl
Run a specific test method
poetry run pytest tests/test_screenshot.py::TestNormalizeUrl::test_url_without_protocol
Run tests with coverage report
poetry run pytest --cov=routes
Run tests in parallel (requires pytest-xdist)
poetry install --with dev pytest-xdist # Install if not already installed
poetry run pytest -n auto
Test Configuration
The 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
Writing New Tests
- 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"