Skip to content

Commit

Permalink
Fix Pytest4.x compatibility errors
Browse files Browse the repository at this point in the history
There are no longer named marker attributes:
pytest-dev/pytest#891

This results in not expecting param `ssl` and leads to errors like:
```
...
test/test_dugong.py::test_http_proxy[plain-None] PASSED                  [  4%]
test/test_dugong.py::test_http_proxy[plain-8080] PASSED                  [  5%]
test/test_dugong.py::test_connect_proxy[plain-None] PASSED               [  6%]
test/test_dugong.py::test_connect_proxy[plain-8080] PASSED               [  7%]
...
test/test_dugong.py::test_http_proxy[ssl-None] FAILED                    [ 51%]
test/test_dugong.py::test_http_proxy[ssl-8080] FAILED                    [ 52%]
test/test_dugong.py::test_connect_proxy[ssl-None] FAILED                 [ 53%]
test/test_dugong.py::test_connect_proxy[ssl-8080] FAILED                 [ 54%]
...

So, the marker `no_ssl` is just ignored.
Let's use the `get_closest_marker` method instead.

Signed-off-by: Stanislav Levin <slev@altlinux.org>
  • Loading branch information
stanislavlevin committed May 29, 2019
1 parent 1ca812f commit 844136b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ formats=bztar
source-dir = rst
build-dir = doc

[tool:pytest]
markers =
no_ssl

13 changes: 10 additions & 3 deletions test/test_dugong.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ def pytest_generate_tests(metafunc):
if not 'http_server' in metafunc.fixturenames:
return

if getattr(metafunc.function, 'no_ssl', False):
params = ('plain',)
if hasattr(metafunc, 'definition'):
if metafunc.definition.get_closest_marker('no_ssl'):
params = ('plain',)
else:
params = ('plain', 'ssl')
else:
params = ('plain', 'ssl')
# pytest < 3.6
if getattr(metafunc.function, 'no_ssl', False):
params = ('plain',)
else:
params = ('plain', 'ssl')

metafunc.parametrize("http_server", params,
indirect=True, scope='module')
Expand Down

0 comments on commit 844136b

Please sign in to comment.