Projet

Général

Profil

0001-tox-generate-only-one-coverage-and-junit-file-32961.patch

Benjamin Dauvergne, 10 mai 2019 11:23

Télécharger (5,73 ko)

Voir les différences:

Subject: [PATCH] tox: generate only one coverage and junit file (#32961)

 Jenkinsfile            | 17 ++++++++++-------
 jenkins.sh             | 14 --------------
 merge-junit-results.py |  5 +++--
 tox.ini                | 32 ++++++++++++++------------------
 4 files changed, 27 insertions(+), 41 deletions(-)
 delete mode 100755 jenkins.sh
Jenkinsfile
10 10
        stage('Unit Tests') {
11 11
            steps {
12 12
                sh "mkdir ${env.TMPDIR}"
13
                sh './jenkins.sh'
13
                sh """
14
virtualenv -p python3 ${env.TMPDIR}/venv/
15
. ${env.TMPDIR}/venv/bin/activate
16
${env.TMPDIR}/venv/bin/pip install tox
17
PGPORT=`python -c 'import struct; import socket; s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'` pg_virtualenv -o fsync=off ${env.TMPDIR}/venv/bin/tox -rv"""
14 18
            }
15 19
            post {
16 20
                always {
17 21
                    script {
18 22
                        utils = new Utils()
19
                        utils.publish_coverage('coverage-*.xml')
20
                        utils.publish_coverage_native(
21
                            'index.html', 'htmlcov-coverage-dj18-authentic-pg', 'Coverage a2')
22
                        utils.publish_coverage_native(
23
                            'index.html', 'htmlcov-coverage-dj18-rbac-pg', , 'Coverage rbac')
23
                        utils.publish_coverage('coverage.xml')
24
                        utils.publish_coverage_native('index.html')
24 25
                        utils.publish_pylint('pylint.out')
26
                        sh './merge-junit-results.py junit-*.xml >junit.xml'
27
                        sh 'rm junit-*.xml'
25 28
                    }
26
                    junit 'junit-*.xml'
29
                    junit 'junit.xml'
27 30
                }
28 31
            }
29 32
        }
jenkins.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
for DIRECTORY in "htmlcov" "htmlcov-coverage-dj18-authentic-pg" "htmlcov-coverage-dj18-rbac-pg" "venv"
6
do
7
    if [ -d "$DIRECTORY" ]; then
8
        rm -r $DIRECTORY
9
    fi
10
done
11

  
12
virtualenv venv
13
venv/bin/pip install tox
14
PGPORT=`python -c 'import struct; import socket; s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'` pg_virtualenv -o fsync=off venv/bin/tox -rv
merge-junit-results.py
3 3
#  Corey Goldberg, Dec 2012
4 4
#
5 5

  
6
from __future__ import print_function
7

  
8 6
import os
9 7
import sys
10 8
import xml.etree.ElementTree as ET
......
42 40
        tests += int(test_suite.attrib['tests'])
43 41
        errors += int(test_suite.attrib['errors'])
44 42
        time += float(test_suite.attrib['time'])
43
        name = test_suite.attrib.get('name', '')
44
        for child in test_suite.getchildren():
45
            child.attrib['classname'] = '%s-%s' % (name, child.attrib.get('classname', ''))
45 46
        cases.append(test_suite.getchildren())
46 47

  
47 48
    new_root = ET.Element('testsuite')
tox.ini
8 8
envlist = py27-coverage-{dj18,dj111}-authentic-{pg,sqlite}-{oldldap,},py27-coverage-{dj18,dj111}-rbac-{pg,sqlite}
9 9

  
10 10
[testenv]
11
# django.contrib.auth is not tested it does not work with our templates
12 11
whitelist_externals =
13 12
  /bin/mv
14 13
setenv =
15 14
  AUTHENTIC2_SETTINGS_FILE=tests/settings.py
16 15
  BRANCH_NAME={env:BRANCH_NAME:}
17
  sqlite: DB_ENGINE=django.db.backends.sqlite3
18
  pg: DB_ENGINE=django.db.backends.postgresql_psycopg2
19
  coverage: COVERAGE=--junitxml=junit-{envname}.xml --cov-report xml --cov-report html --cov=src/ --cov-config .coveragerc
16

  
20 17
  authentic: DJANGO_SETTINGS_MODULE=authentic2.settings
21 18
  rbac: DJANGO_SETTINGS_MODULE=django_rbac.test_settings
19

  
20
  authentic: TESTS=tests/
21
  authentic-oldldap: TESTS=tests/test_ldap.py
22
  rbac: TESTS=tests_rbac/
23

  
24
  sqlite: DB_ENGINE=django.db.backends.sqlite3
25
  pg: DB_ENGINE=django.db.backends.postgresql_psycopg2
26

  
27
  JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml}
28
  coverage: COVERAGE=--cov=src --cov-branch --cov-append --cov-report xml --cov-report html
22 29
  fast: FAST=--nomigrations
23 30
  reusedb: REUSEDB=--reuse-db
24
  A2_TESTS=tests
25
  oldldap: A2_TESTS=tests/test_ldap.py
31

  
32
  # support for pg_virtualenv
26 33
  PGPORT={env:PGPORT:}
27 34
  PGHOST={env:PGHOST:}
28 35
  PGUSER={env:PGUSER:}
......
60 67
  oldldap: python-ldap<3
61 68
commands =
62 69
  ./getlasso.sh
63
  authentic: py.test {env:FAST:} {env:REUSEDB:} {env:COVERAGE:} {posargs:{env:A2_TESTS:tests/} --random-group}
64
  rbac: py.test {env:FAST:} {env:REUSEDB:} {env:COVERAGE:} {posargs:tests_rbac/}
65
  coverage: mv coverage.xml coverage-{envname}.xml
66
  coverage-dj18-authentic-pg: mv htmlcov htmlcov-coverage-dj18-authentic-pg
67
  coverage-dj18-rbac-pg: mv htmlcov htmlcov-coverage-dj18-rbac-pg
68
  coverage-dj18-authentic-pg: ./pylint.sh src/authentic2/
69

  
70

  
71
[testenv:check]
72
deps = prospector[with_pyroma]
73
commands = python -m compileall -fq {toxinidir}/src
74
           prospector --with-tool pyroma {toxinidir}/src
70
  rbac,authentic: py.test {env:FAST:} {env:REUSEDB:} {env:COVERAGE:} {env:JUNIT:} {posargs:{env:TESTS} --random-group}
75 71

  
76 72
[pytest]
77 73
filterwarnings =
78
-