diff options
author | holger krekel <holger@merlinux.eu> | 2013-08-02 09:52:40 +0200 |
---|---|---|
committer | holger krekel <holger@merlinux.eu> | 2013-08-02 09:52:40 +0200 |
commit | 7d86827b5edfaeaff8d6bcf968ffaae5534e806a (patch) | |
tree | 3f58e549cbb0e663c3a58a9f41b02d38cb1771ed /_pytest/main.py | |
parent | b2ebb808785d8e52eea3cb9316c394259ff285d9 (diff) | |
download | pytest-7d86827b5edfaeaff8d6bcf968ffaae5534e806a.tar.gz |
ref #322 cleanup all teardown calling to only happen when setup succeeded.
don't use autouse fixtures for now because it would cause a proliferation
and overhead for the execution of every test. Rather introduce a
node.addfinalizer(fin) to attach a finalizer to the respective node
and call it from node.setup() functions if the setup phase succeeded
(i.e. there is no setup function or it finished successfully)
Diffstat (limited to '_pytest/main.py')
-rw-r--r-- | _pytest/main.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/_pytest/main.py b/_pytest/main.py index de3a43822..2d1152423 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -41,7 +41,7 @@ def pytest_addoption(parser): help="run pytest in strict mode, warnings become errors.") group = parser.getgroup("collect", "collection") - group.addoption('--collectonly', '--collect-only', action="store_true", + group.addoption('--collectonly', '--collect-only', action="store_true", help="only collect tests, don't execute them."), group.addoption('--pyargs', action="store_true", help="try to interpret all arguments as python packages.") @@ -326,6 +326,14 @@ class Node(object): def getplugins(self): return self.config._getmatchingplugins(self.fspath) + def addfinalizer(self, fin): + """ register a function to be called when this node is finalized. + + This method can only be called when this node is active + in a setup chain, for example during self.setup(). + """ + self.session._setupstate.addfinalizer(fin, self) + def getparent(self, cls): current = self while current and not isinstance(current, cls): |