[Pytest-commit] Issue #517: setup_method executed before session fixtures (hpk42/pytest)

Haak Saxberg issues-reply at bitbucket.org
Thu May 15 13:18:36 CEST 2014


New issue 517: setup_method executed before session fixtures
https://bitbucket.org/hpk42/pytest/issue/517/setup_method-executed-before-session

Haak Saxberg:

consider the following dummy test file: 
```
#!python

import pytest

@pytest.yield_fixture(scope="session", autouse=True)
def print_session():
    print "session fixture"
    yield
    print "session teardown"


class TestClass(object):

    def setup_method(self, method):
        print "method setup"

    def teardown_method(self, method):
        print "method teardown"

    def test_printer(self):
        print "test method"
```

`pytest --capture=no test_file.py` will generate the following output:

```
#!bash

==================== test session starts ====================
platform darwin -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2
collected 1 items

tests/test_ordering.py method setup
session fixture
test method
.method teardown
session teardown


================= 1 passed in 0.01 seconds =================
```

that doesn't seem right, especially since the teardowns are in the correct order. In fact it's pretty bad, because you might (I would think rightly) depend on the session having been set up already in your setup_method.




More information about the pytest-commit mailing list