Commit 500e9b22 authored by Anton Akhmerov's avatar Anton Akhmerov

Merge branch 'test/pytest-cov-upstream' into 'master'

Add test coverage tools

See merge request !146
parents 227e0d4b 3f19d623
......@@ -90,4 +90,12 @@ build/
# webpack analyze data
\ No newline at end of file
# JetBrains IDE folders
# pytest coverage reports
# This base image can be found in 'Dockerfile'
image: zesje/base
......@@ -36,11 +35,6 @@ test_js:
stage: test
script: yarn test:js
<<: *python_packages
stage: test
script: yarn test:py
<<: *node_modules
stage: test
......@@ -54,3 +48,13 @@ lint_py:
allow_failure: true
- yarn lint:py
<<: *python_packages
stage: test
- yarn test:py:cov
- cov.html/
expire_in: 1 week
[![coverage report](](
# Welcome to Zesje
Zesje is an online grading system for written exams.
......@@ -63,6 +65,33 @@ or `zesje/`.
You can run the tests by running
yarn test
#### Viewing test coverage
As a test coverage tool for Python tests, `pytest-cov` is used.
To view test coverage, run
yarn test:py:cov
A coverage report is now generated in the terminal, as an XML file, and in HTML format.
The HTML file shows an overview of untested code in red.
##### Viewing coverage in Visual Studio Code
There is a plugin called Coverage Gutter that will highlight which lines of code are covered.
Simply install Coverage Gutter, after which a watch button appears in the colored box at the bottom of your IDE.
When you click watch, green and red lines appear next to the line numbers indicating if the code is covered.
Coverage Gutter uses the XML which is produced by `yarn test:py:cov`, called `cov.xml`. This file should be located in the main folder.
##### Viewing coverage in PyCharm
To view test coverage in PyCharm, run `yarn test:py:cov` to generate the coverage report XML file `cov.xml` if it is not present already.
Next, open up PyCharm and in the top bar go to **Run -> Show Code Coverage Data** (Ctrl + Alt + F6).
Press **+** and add the file `cov.xml` that is in the main project directory.
A code coverage report should now appear in the side bar on the right.
#### Policy errors
......@@ -3,7 +3,7 @@
"main": "index.js",
"license": "AGPL-3.0",
"scripts": {
"dev": "concurrently --kill-others --names \"WEBPACK,PYTHON,CELERY\" --prefix-colors \"bgBlue.bold,bgGreen.bold,bgRed.bold\" \"webpack-dev-server --hot --inline --progress --config\" \"ZESJE_SETTINGS=$(pwd)/ python3 zesje\" \"ZESJE_SETTINGS=$(pwd)/ celery -A zesje.celery worker -l info --autoscale=4,1 --max-tasks-per-child=16 \"",
"dev": "concurrently --kill-others --names \"WEBPACK,PYTHON,CELERY\" --prefix-colors \"bgBlue.bold,bgGreen.bold,bgRed.bold\" \"webpack-dev-server --hot --inline --progress --config\" \"ZESJE_SETTINGS=$(pwd)/ python3 zesje\" \"ZESJE_SETTINGS=$(pwd)/ celery -A zesje.celery worker\"",
"build": "webpack --config",
"ci": "yarn lint; yarn test",
"lint": "yarn lint:js; yarn lint:py",
......@@ -16,7 +16,9 @@
"analyze": "webpack --config --profile --json > stats.json; webpack-bundle-analyzer stats.json zesje/static",
"migrate:dev": "ZESJE_SETTINGS=$(pwd)/ FLASK_APP=zesje/ flask db upgrade",
"migrate": "FLASK_APP=zesje/ flask db upgrade",
"prepare-migration": "ZESJE_SETTINGS=$(pwd)/ FLASK_APP=zesje/ flask db migrate"
"prepare-migration": "ZESJE_SETTINGS=$(pwd)/ FLASK_APP=zesje/ flask db migrate",
"test:py:cov": "python3 -m pytest -v -W error::RuntimeWarning --cov=zesje --cov-report=xml:cov.xml --cov-report=html:cov.html --cov-report=term tests/",
"migrate-down": "FLASK_APP=zesje/ flask db downgrade"
"standard": {
"parser": "babel-eslint",
# Tests
# Linting
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment