summaryrefslogtreecommitdiff
path: root/pytest_helpers_namespace
diff options
context:
space:
mode:
Diffstat (limited to 'pytest_helpers_namespace')
-rw-r--r--pytest_helpers_namespace/plugin.py35
-rw-r--r--pytest_helpers_namespace/version.py4
2 files changed, 31 insertions, 8 deletions
diff --git a/pytest_helpers_namespace/plugin.py b/pytest_helpers_namespace/plugin.py
index 95ab3e5..4eb7239 100644
--- a/pytest_helpers_namespace/plugin.py
+++ b/pytest_helpers_namespace/plugin.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
- :copyright: © 2016-2017 by the SaltStack Team, see AUTHORS for more details.
+ :copyright: © 2016-2019 by the SaltStack Team, see AUTHORS for more details.
:license: Apache 2.0, see LICENSE for more details.
@@ -14,6 +14,9 @@
# Import python libs
from functools import partial, wraps
+# Import 3rd-party libs
+import pytest
+
class FuncWrapper(object):
@@ -86,8 +89,28 @@ class HelpersRegistry(object):
)
-def pytest_namespace():
- '''
- Register our own namespace with pytest
- '''
- return {'helpers': HelpersRegistry()}
+if tuple([int(part) for part in pytest.__version__.split('.') if part.isdigit()]) < (4, 1):
+ # PyTest < 4.1
+ def pytest_namespace():
+ '''
+ Register our own namespace with pytest
+ '''
+ return {'helpers': HelpersRegistry()}
+else:
+ # PyTest >= 4.1
+ # This now uses the stop gap provided in:
+ # https://docs.pytest.org/en/latest/deprecations.html#pytest-namespace
+ #
+ # We however use `pytest_load_initial_conftests` because we need to "patch"
+ # pytest before any conftest is loaded.
+ def pytest_load_initial_conftests(early_config, parser, args):
+ try:
+ pytest.helpers
+ except AttributeError:
+ pytest.helpers = HelpersRegistry()
+
+ def pytest_unconfigure():
+ try:
+ delattr(pytest, 'helpers')
+ except AttributeError:
+ pass
diff --git a/pytest_helpers_namespace/version.py b/pytest_helpers_namespace/version.py
index 12bc370..b242d2e 100644
--- a/pytest_helpers_namespace/version.py
+++ b/pytest_helpers_namespace/version.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
- :copyright: © 2016-2017 by the SaltStack Team, see AUTHORS for more details.
+ :copyright: © 2016-2019 by the SaltStack Team, see AUTHORS for more details.
:license: Apache 2.0, see LICENSE for more details.
@@ -16,5 +16,5 @@
from __future__ import absolute_import
-__version_info__ = (2017, 11, 11)
+__version_info__ = (2019, 1, 8)
__version__ = '{0}.{1}.{2}'.format(*__version_info__)