# Python
# Django configuration example
default:
workspace: shared
stages:
- test
jobs:
- name: coverage
stage: test
image: khoanld98/sun_ci_django
services:
- image: mysql:5.7
name: user_test
environment:
MYSQL_DATABASE: user_test
MYSQL_USER: user_test
MYSQL_PASSWORD: user_test
MYSQL_ROOT_PASSWORD: user_test
environment:
APP_ENV: testing
before_script:
- pip install -r requirements.txt
- python manage.py migrate
script:
- coverage run manage.py test
- coverage xml
- coverage html
coverage:
type: clover
path: htmlcov
artifacts:
paths:
- htmlcov
expires_in: 3 days
- name: convention
stage: test
image: pipelinecomponents/flake8
script:
- flake8 --version
add sun_ci.yml
file to your project root directory.
# Run unit test with coverage package
Run unit test sun_ci_django.
The docker using python version 3.7
Coverage has a number of commands:
run - Run a Python program and collect execution data.
combine – Combine together a number of data files.
erase – Erase previously collected coverage data.
report – Report coverage results.
html – Produce annotated HTML listings with coverage results.
xml – Produce an XML report with coverage results.
json – Produce a JSON report with coverage results.
annotate – Annotate source files with coverage results.
debug – Get diagnostic information.
# Check convention with flake8 package
Using flake8 docker image written by gitlab-ci on docker hub.
Run follow command to see option of flake8.
Usage: flake8 [options] file file ...
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-v, --verbose Print more information about what is happening in
flake8. This option is repeatable and will increase
verbosity each time it is repeated.
-q, --quiet Report only file names, or nothing. This option is
repeatable.
--count Print total number of errors and warnings to standard
error and set the exit code to 1 if total is not
empty.
--diff Report changes only within line number ranges in the
unified diff provided on standard in by the user.
--exclude=patterns Comma-separated list of files or directories to
exclude.(Default:
.svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg)
--filename=patterns Only check for filenames matching the patterns in this
comma-separated list. (Default: *.py)
--format=format Format errors according to the chosen formatter.
--hang-closing Hang closing bracket instead of matching indentation
of opening bracket's line.
--ignore=errors Comma-separated list of errors and warnings to ignore
(or skip). For example, ``--ignore=E4,E51,W234``.
(Default: E121,E123,E126,E226,E24,E704)
--extend-ignore=errors
Comma-separated list of errors and warnings to add to
the list of ignored ones. For example, ``--extend-
ignore=E4,E51,W234``.
--max-line-length=n Maximum allowed line length for the entirety of this
run. (Default: 79)
--select=errors Comma-separated list of errors and warnings to enable.
For example, ``--select=E4,E51,W234``. (Default: )
--extend-select errors
Comma-separated list of errors and warnings to add to
the list of selected ones. For example, ``--extend-
select=E4,E51,W234``.
--disable-noqa Disable the effect of "# noqa". This will report
errors on lines with "# noqa" at the end.
--show-source Show the source generate each error or warning.
--statistics Count errors and warnings.
--enabled-extensions=ENABLED_EXTENSIONS
Enable plugins and extensions that are otherwise
disabled by default
--exit-zero Exit with status code "0" even if there are errors.
-j JOBS, --jobs=JOBS Number of subprocesses to use to run checks in
parallel. This is ignored on Windows. The default,
"auto", will auto-detect the number of processors
available to use. (Default: auto)
--output-file=OUTPUT_FILE
Redirect report to a file.
--tee Write to stdout and output-file.
--append-config=APPEND_CONFIG
Provide extra config files to parse in addition to the
files found by Flake8 by default. These files are the
last ones read and so they take the highest precedence
when multiple files provide the same option.
--config=CONFIG Path to the config file that will be the authoritative
config source. This will cause Flake8 to ignore all
other configuration files.
--isolated Ignore all configuration files.
--builtins=BUILTINS define more built-ins, comma separated
--doctests check syntax of the doctests
--include-in-doctest=INCLUDE_IN_DOCTEST
Run doctests only on these files
--exclude-from-doctest=EXCLUDE_FROM_DOCTEST
Skip these files when running doctests