The backend of SheepVibes is written in Python and uses the pytest framework for testing.
We use flake8 for Python linting.
flake8 backend/ --max-line-length=120- Navigate to the backend directory. Install the necessary development dependencies within a Python virtual environment, including
pytest:# From the project root python -m venv venv source venv/bin/activate pip install --upgrade pip pip install -r backend/requirements.txt -r backend/requirements-dev.txt
The backend tests require a running Redis instance for caching checks.
-
Start Redis Before running the tests, start a Redis container. The
--rmflag will ensure it is automatically removed when stopped.# Using Podman podman run -d --rm --name sheepvibes-test-redis -p 6379:6379 redis:alpine # Or using Docker # docker run -d --rm --name sheepvibes-test-redis -p 6379:6379 redis:alpine
-
Run Pytest Ensure you are in the project root (not
backend). The test suite is configured viapytest.ini(intests/) to automatically connect to Redis onlocalhost:6379.# From the project root python -m pytest -c tests/pytest.ini tests/ -v -
Stop Redis After you've finished testing, you can stop the Redis container.
podman stop sheepvibes-test-redis
The project includes a robust development environment managed by scripts/dev_manager.sh.
-
Start Dev Environment This will build the image, start Redis, and launch the Backend App in Debug Mode (Flask development server).
./scripts/dev_manager.sh up
- The app runs at
http://localhost:5002(default). - Code changes are hot-reloaded automatically.
- The app runs at
-
Verify Production Parity To test the application as it runs in production (using Gunicorn), use the
--prodflag:./scripts/dev_manager.sh up --prod
Currently, there are no automated tests specifically for the frontend JavaScript code.
For a vanilla JavaScript application like this, End-to-End (E2E) testing would be a valuable addition. Suitable E2E testing tools include:
- Playwright: https://playwright.dev/
- Cypress: https://www.cypress.io/
To ensure code quality, the project uses a GitHub Actions workflow to run backend tests on every push and pull request. This workflow serves as the definitive guide for setting up an automated testing environment.
The workflow is defined in .github/workflows/run-tests.yml.
The key is to follow the instructions given above, and replicate the setup found in our GitHub Actions workflow, paying close attention to the use of service containers and the CACHE_REDIS_PORT environment variable for dynamic port mapping.