[TIP] pytest fixture autouse question
holger at merlinux.eu
Fri Jan 4 01:56:42 PST 2013
On Thu, Jan 03, 2013 at 14:20 -0500, Pella,Chris wrote:
> I may have a misunderstanding of when session-level autouse fixtures are called. I am trying to create a session level fixture that runs before once per test session before any class setup is called.
It's a known issue of mixing xUnit and pytest style fixtures. See here
for a discussion and the planned resolution:
For now, you can work around the issue like this::
This will execute after th "session" scoped installer that you describe
> I have conftest.py file in the directory where the tests reside and in there I have some code that installs some client software on the test node. We only want to install the client once per session for all the test classes that get executed.
> def installer_fixture(request):
> Installs client at the session level
> print "installing"
> client = InstallClient()
> def uninstall():
> Uninstall client
> I assumed that this would execute prior to any test setup for a particular test class since it is a session level fixture, but I find that setup_class() executes before the clients get installed.
> e.g. with some toy test code I find that the class setup gets executed before the fixture. This is not the behaviour I wanted or expected.
> import pytest
> class TestMe:
> def setup_class(cls):
> print "setup"
> def test_one(cls):
> print "test one"
> def teardown_class(cls):
> print "teardown"
> The information contained in this electronic mail transmission
> may be privileged and confidential, and therefore, protected
> from disclosure. If you have received this communication in
> error, please notify us immediately by replying to this
> message and deleting it from your computer without copying
> or disclosing it.
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
More information about the testing-in-python