diff --git a/_pytest/mark.py b/_pytest/mark.py index a06b02b14..ccc90d6e8 100644 --- a/_pytest/mark.py +++ b/_pytest/mark.py @@ -66,10 +66,8 @@ class MarkerError(Exception): """Error in use of a pytest marker/attribute.""" - def pytest_namespace(): return { - 'mark': MarkGenerator(), 'param': ParameterSet.param, } @@ -225,9 +223,13 @@ def matchkeyword(colitem, keywordexpr): def pytest_configure(config): - import pytest + config._old_mark_config = MARK_GEN._config if config.option.strict: - pytest.mark._config = config + MARK_GEN._config = config + + +def pytest_unconfigure(config): + MARK_GEN._config = config._old_mark_config class MarkGenerator(object): @@ -241,11 +243,13 @@ class MarkGenerator(object): will set a 'slowtest' :class:`MarkInfo` object on the ``test_function`` object. """ + _config = None + def __getattr__(self, name): if name[0] == "_": raise AttributeError("Marker name must NOT start with underscore") - if hasattr(self, '_config'): + if self._config is not None: self._check(name) return MarkDecorator(Mark(name, (), {})) @@ -263,6 +267,7 @@ class MarkGenerator(object): if name not in self._markers: raise AttributeError("%r not a registered marker" % (name,)) + def istestfunc(func): return hasattr(func, "__call__") and \ getattr(func, "__name__", "") != "" @@ -384,3 +389,6 @@ class MarkInfo(object): def __iter__(self): """ yield MarkInfo objects each relating to a marking-call. """ return imap(MarkInfo, self._marks) + + +MARK_GEN = MarkGenerator() diff --git a/pytest.py b/pytest.py index 518b65a38..95cb8ccc6 100644 --- a/pytest.py +++ b/pytest.py @@ -20,6 +20,7 @@ __all__ = [ 'skip', 'importorskip', 'exit', + 'mark', ] @@ -41,6 +42,7 @@ from _pytest import __version__ from _pytest.debugging import pytestPDB as __pytestPDB from _pytest.recwarn import warns, deprecated_call from _pytest.runner import fail, skip, importorskip, exit +from _pytest.mark import MARK_GEN as mark set_trace = __pytestPDB.set_trace _preloadplugins() # to populate pytest.* namespace so help(pytest) works