diff --git a/Jenkinsfile b/Jenkinsfile index 3d88eaea9..5db04fa33 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,6 +35,7 @@ PGPORT=`python -c 'import struct; import socket; s=socket.socket(); s.setsockopt sh """ virtualenv -p python3 ${env.TMPDIR}/venv/ ${env.TMPDIR}/venv/bin/pip install tox +PYTESTOPTIONS=--slow \ 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 -r""" } post { diff --git a/tests/conftest.py b/tests/conftest.py index 1b0b808e4..dc5476c39 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -45,6 +45,29 @@ from authentic2.authentication import OIDCUser from . import utils + +def pytest_addoption(parser): + parser.addoption( + "--slow", + action="store_true", + help="run slow tests", + ) + + +def pytest_configure(config): + # register an additional marker + config.addinivalue_line( + "markers", "slow: mark test as slow" + ) + + +def pytest_runtest_setup(item): + markers = list(item.iter_markers(name='slow')) + slow = item.config.getoption('--slow') + if markers and not slow: + pytest.skip('slow tests must not run') + + Role = get_role_model() diff --git a/tests_rbac/conftest.py b/tests_rbac/conftest.py new file mode 100644 index 000000000..55f512aa9 --- /dev/null +++ b/tests_rbac/conftest.py @@ -0,0 +1,39 @@ +# authentic2 - versatile identity manager +# Copyright (C) 2010-2020 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import pytest + + +def pytest_addoption(parser): + parser.addoption( + "--slow", + action="store_true", + help="run slow tests", + ) + + +def pytest_configure(config): + # register an additional marker + config.addinivalue_line( + "markers", "slow: mark test as slow" + ) + + +def pytest_runtest_setup(item): + markers = list(item.iter_markers(name='slow')) + slow = item.config.getoption('--slow') + if markers and not slow: + pytest.skip('slow tests must not run') diff --git a/tests_rbac/test_rbac.py b/tests_rbac/test_rbac.py index b556c23fa..8a54a9117 100644 --- a/tests_rbac/test_rbac.py +++ b/tests_rbac/test_rbac.py @@ -1,4 +1,19 @@ -import pytest +# authentic2 - versatile identity manager +# Copyright (C) 2010-2020 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import time from django.contrib.auth import get_user_model @@ -6,9 +21,10 @@ from django.contrib.contenttypes.models import ContentType from django.test.utils import CaptureQueriesContext from django.db import connection - from django_rbac import utils, models, backends +import pytest + def test_role_parenting(db): OrganizationalUnit = utils.get_ou_model() @@ -70,6 +86,7 @@ SIZE = 1000 SPAN = 50 +@pytest.mark.slow def test_massive_role_parenting(db): User = get_user_model() diff --git a/tox.ini b/tox.ini index e42560d10..d4e485ac2 100644 --- a/tox.ini +++ b/tox.ini @@ -37,6 +37,7 @@ setenv = fast: FAST=--nomigrations reusedb: REUSEDB=--reuse-db !nosw: SW={tty:--sw:} + slow: PYTESTOPTIONS={env:PYTESTOPTIONS:} --slow passenv= BRANCH_NAME # support for pg_virtualenv @@ -44,6 +45,7 @@ passenv= PGHOST PGUSER PGPASSWORD + PYTESTOPTIONS deps = pip > 9 dj111: django<2.0 @@ -65,6 +67,7 @@ deps = httmock pytz pytest-freezegun + faker enum34<=1.1.6 ldaptools>=0.15 oldldap: python-ldap<3 @@ -78,7 +81,7 @@ commands = py2: ./getlasso.sh py3: ./getlasso3.sh authentic: ./check-migrations.sh - rbac,authentic: py.test {env:FAST:} {env:REUSEDB:} {env:COVERAGE:} {env:JUNIT:} {env:SW:} {posargs:{env:TESTS} --random-group} + rbac,authentic: py.test {env:PYTESTOPTIONS:} {env:FAST:} {env:REUSEDB:} {env:COVERAGE:} {env:JUNIT:} {env:SW:} {posargs:{env:TESTS} --random-group} [testenv:pylint] basepython = python2.7