Running tests
E2E tests
Initial steps:
- Run CVAT instance:
- Add test user in CVAT:
- Install npm dependencies:
cd tests yarn --frozen-lockfile
If you want to get a code coverage report, instrument the code:
yarn --frozen-lockfile
yarn run coverage
Running tests
yarn run cypress:run:chrome
yarn run cypress:run:chrome:canvas3d
REST API, SDK and CLI tests
Initial steps
- Follow this guide to prepare
cvat-sdk
andcvat-cli
source code - Install all necessary requirements before running REST API tests:
pip install -r ./tests/python/requirements.txt pip install -e ./cvat-sdk pip install -e ./cvat-cli
- Stop any other CVAT containers which you run previously. They keep ports which are used by containers for the testing system.
Running tests
Run all REST API tests:
pytest ./tests/python
This command will automatically start all necessary docker containers.
If you want to start/stop these containers without running tests use special options for it:
pytest ./tests/python --start-services
pytest ./tests/python --stop-services
If you need to rebuild your CVAT images add --rebuild
option:
pytest ./tests/python --rebuild
If you want to get a code coverage report, use special option for it:
COVERAGE_PROCESS_START=.coveragerc pytest ./tests/python --rebuild --cov --cov-report xml
Debugging
Currently, this is only supported in deployments based on Docker Compose, which should be enough to fix errors arising in REST API tests.
To debug a server deployed with Docker, you need to do the following:
-
Adjust env variables in the
docker-compose.dev.yml
file for your test case -
Rebuild the images and start the test containers:
Now, you can use VS Code tasks to attach to the running server containers. To attach to a container, run one of the following tasks:
REST API tests: Attach to server
for the server containerREST API tests: Attach to RQ low
for the low priority queue workerREST API tests: Attach to RQ default
for the default priority queue worker
If you have a custom development environment setup, you need to adjust host-remote path mappings in the
.vscode/launch.json
:
Extra options:
- If you want the server to wait for a debugger on startup,
use the
CVAT_DEBUG_WAIT_CLIENT
environment variable: - If you want to change the default debugging ports, check the
*_DEBUG_PORT
variables in thedocker-compose.dev.yml
Unit tests
Initial steps
- Install necessary Python dependencies:
pip install -r cvat/requirements/testing.txt
- Install npm dependencies:
yarn --frozen-lockfile
- Build CVAT server image
docker compose -f docker-compose.yml -f docker-compose.dev.yml build cvat_server
- Run cvat_opa container
docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d cvat_opa
Running tests
- Python tests
python manage.py test --settings cvat.settings.testing cvat/apps -v 2
If you want to get a code coverage report, run the next command:
coverage run manage.py test --settings cvat.settings.testing cvat/apps -v 2
- JS tests
cd cvat-core yarn run test
Debug python unit tests
- Run
server: tests
debug task in VSCode - If you want to debug particular tests then change the configuration
of the corresponding task in
./vscode/launch.json
, for example:
IAM and Open Policy Agent tests
Generate tests
Run testing
- In a Docker container
- or execute OPA directly
Linting Rego
The Rego policies in this project are linted using Regal.
- In a Docker container
- or execute Regal directly