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/
data-dev
# webpack analyze data
stats.json
\ No newline at end of file
stats.json
# JetBrains IDE folders
.idea/
# pytest coverage reports
.coverage
cov.xml
cov.html/
# This base image can be found in 'Dockerfile'
image: zesje/base
......@@ -36,11 +35,6 @@ test_js:
stage: test
script: yarn test:js
test_py:
<<: *python_packages
stage: test
script: yarn test:py
lint_js:
<<: *node_modules
stage: test
......@@ -54,3 +48,13 @@ lint_py:
allow_failure: true
script:
- yarn lint:py
test_py:
<<: *python_packages
stage: test
script:
- yarn test:py:cov
artifacts:
paths:
- cov.html/
expire_in: 1 week
[![coverage report](https://gitlab.kwant-project.org/zesje/zesje/badges/master/coverage.svg)](https://gitlab.kwant-project.org/zesje/zesje/commits/master)
# 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 webpack.dev.js\" \"ZESJE_SETTINGS=$(pwd)/zesje.dev.cfg python3 zesje\" \"ZESJE_SETTINGS=$(pwd)/zesje.dev.cfg 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 webpack.dev.js\" \"ZESJE_SETTINGS=$(pwd)/zesje.dev.cfg python3 zesje\" \"ZESJE_SETTINGS=$(pwd)/zesje.dev.cfg celery -A zesje.celery worker\"",
"build": "webpack --config webpack.prod.js",
"ci": "yarn lint; yarn test",
"lint": "yarn lint:js; yarn lint:py",
......@@ -16,7 +16,9 @@
"analyze": "webpack --config webpack.prod.js --profile --json > stats.json; webpack-bundle-analyzer stats.json zesje/static",
"migrate:dev": "ZESJE_SETTINGS=$(pwd)/zesje.dev.cfg FLASK_APP=zesje/__init__.py flask db upgrade",
"migrate": "FLASK_APP=zesje/__init__.py flask db upgrade",
"prepare-migration": "ZESJE_SETTINGS=$(pwd)/zesje.dev.cfg FLASK_APP=zesje/__init__.py flask db migrate"
"prepare-migration": "ZESJE_SETTINGS=$(pwd)/zesje.dev.cfg FLASK_APP=zesje/__init__.py 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/__init__.py flask db downgrade"
},
"standard": {
"parser": "babel-eslint",
......
# Tests
pytest
pyssim
pytest-cov
# Linting
flake8
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment