[py-dev] [hpk42/pytest] Naming test methods "setup" causes different behavior (issue #190)
Alex Okrushko
issues-reply at bitbucket.org
Fri Sep 21 23:22:15 CEST 2012
--- you can reply above this line ---
New issue 190: Naming test methods "setup" causes different behavior
https://bitbucket.org/hpk42/pytest/issue/190/naming-test-methods-setup-causes-different
Alex Okrushko:
depending on the name of the setup-method the behavior is completely different:
1-st scenario:
{{{
#!python
class TestMyProp(object):
@pytest.setup(scope = "class")
def stp(self):
self.prop = "init"
print self.prop
def test_prop(self):
TestMyProp.prop = "changed"
print self.prop
def test_prop_again(self):
print self.prop
}}}
OUTPUT: py.test -sq
{{{
#!output
============================= test session starts ==============================
platform win32 -- Python 2.7.3 -- pytest-2.3.0.dev15
collecting ... collected 2 items
my_test.py init
changed
.changed
.
=========================== 2 passed in 0.01 seconds ===========================
}}}
This is the expected result.
NOW change the name of the method to "setup":
{{{
#!python
class TestMyProp(object):
@pytest.setup(scope = "class")
def setup(self):
self.prop = "init"
print self.prop
def test_prop(self):
TestMyProp.prop = "changed"
print self.prop
def test_prop_again(self):
print self.prop
}}}
and the output becomes:
{{{
#!output
============================= test session starts ==============================
platform win32 -- Python 2.7.3 -- pytest-2.3.0.dev15
collecting ... collected 2 items
my_test.py init
init
init
.init
init
.
=========================== 2 passed in 0.02 seconds ===========================
}}}
--
This is an issue notification from bitbucket.org. You are receiving
this either because you are the owner of the issue, or you are
following the issue.
More information about the Pytest-dev
mailing list