Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naming test methods "setup" causes different behavior #190

Closed
pytestbot opened this issue Sep 21, 2012 · 2 comments
Closed

Naming test methods "setup" causes different behavior #190

pytestbot opened this issue Sep 21, 2012 · 2 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Alex Okrushko (BitBucket: alex_okrushko, GitHub: 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 ===========================

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


That's a bug in the development version. I just fixed it, you can install dev16 with "pip install -i http://pypi.testrun.org -U pytest".

Note, btw, that the development version might still see some changes before release, particularly we consider going for @pytest.fixture instead of @pytest.setup.

@pytestbot
Copy link
Contributor Author

Original comment by Alex Okrushko (BitBucket: alex_okrushko, GitHub: alex_okrushko):


Thanks Holger! Could also please write the example in the docs how to do the setup/teardown within the class declaration. :) I've managed to do the setup, however cannot figure out the teardown. Also, is there any way to use the "request" within class? Thanks for your hard work!

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
fkohlgrueber pushed a commit to fkohlgrueber/pytest that referenced this issue Oct 27, 2018
Just executing ``black`` without any argument does not print any message
to stdout or stderr. It's rather confusing, because the user doesn't
know what happened.

In ``len(sources) == 0`` case, black now prints ``No paths given. Nothing to
do``.

Signed-off-by: Christian Heimes <christian@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant