[TIP] pytest fixture autouse question

Pella,Chris Chris.Pella at safenet-inc.com
Thu Jan 3 11:20:47 PST 2013


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.

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.

@pytest.fixture(scope="session",autouse=True)
def installer_fixture(request):
    """
    Installs client at the session level
    """
    print "installing"
    client = InstallClient()
    client.install()
    time.sleep(60)

    def uninstall():
        """
        Uninstall client
        """
        client.uninstall()

    request.addfinalizer(uninstall)


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):
        pytest.set_trace()
        print "setup"

    def test_one(cls):
        print "test one"

    def teardown_class(cls):
        print "teardown"




Thanks,
chris

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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20130103/ca9062e3/attachment.htm>


More information about the testing-in-python mailing list