Skip to content

Commit e9a3a9d

Browse files
committed
test_ssl.py: make ssl testing possible with "--ssl" option to pytest
Run ssl tests only when '--ssl' is specified. This enables the session scope level 'httpserver_ssl_context' which could affect other tests and as it is session based, it needs to be run in a separate test run from the other tests.
1 parent b8698ee commit e9a3a9d

5 files changed

Lines changed: 24 additions & 1 deletion

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ clean: cov-clean doc-clean
3131
.PHONY: quick-test
3232
quick-test:
3333
.venv/bin/pytest tests -s -vv
34+
.venv/bin/pytest tests -s -vv --ssl
3435

3536
.PHONY: test
3637
test:
@@ -43,6 +44,7 @@ test-pdb:
4344
.PHONY: cov
4445
cov: cov-clean
4546
.venv/bin/coverage run -m pytest -vv tests
47+
.venv/bin/coverage run -a -m pytest -vv tests --ssl
4648
.venv/bin/coverage xml
4749

4850
.PHONY: cov-clean

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ test=pytest
33

44
[flake8]
55
max-line-length = 145
6+
7+
[tool:pytest]
8+
markers =
9+
ssl: set up ssl context

tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
import pytest
3+
4+
5+
def pytest_addoption(parser):
6+
parser.addoption("--ssl", action="store_true", default=False, help="run ssl tests")
7+
8+
9+
def pytest_runtest_setup(item):
10+
markers = [marker.name for marker in item.iter_markers()]
11+
if not item.config.getoption("--ssl") and "ssl" in markers:
12+
pytest.skip()
13+
if item.config.getoption("--ssl") and "ssl" not in markers:
14+
pytest.skip()

tests/test_ssl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
import requests
7+
pytestmark = pytest.mark.ssl
78

89
test_dir = os.path.dirname(os.path.realpath(__file__))
910
assets_dir = pjoin(test_dir, "assets")

tox.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ envlist =
55
py36
66
py36-env
77
py37
8+
py38
89

910
[testenv]
1011
commands =
1112
pip install -e .[test]
12-
pytest
13+
pytest -vv
14+
pytest -vv --ssl
1315

1416

1517
[testenv:py36-env]

0 commit comments

Comments
 (0)