Issues

Issue #220 invalid

setup_class was not set correctly as class level

Anonymous avatarAnonymous created an issue

test_d.py source: setup_class was called for each test cases, while teardown was called once

import pytest
import imp, sys, subprocess

class TestD:

    @classmethod    
    def setup_class(cls):  
        print 1/0


    def test_ssl_exchange_cert(self):          
        assert 1==1


    def test_verify(self):

        assert 1==1

    @classmethod            
    def teardown_class(cls):        
        print 1/0

Output from console

============================= test session starts ==============================
platform linux2 -- Python 2.7.3 -- pytest-2.2.4
collecting ... collected 2 items

test_d.py EEE

==================================== ERRORS ====================================
________________ ERROR at setup of TestD.test_ssl_exchange_cert ________________

cls = <class test_d.TestD at 0x8738fbc>

    @classmethod
    def setup_class(cls):
>       print 1/0
E       ZeroDivisionError: integer division or modulo by zero

test_d.py:8: ZeroDivisionError
_____________________ ERROR at setup of TestD.test_verify ______________________

cls = <class test_d.TestD at 0x8738fbc>

    @classmethod
    def setup_class(cls):
>       print 1/0
E       ZeroDivisionError: integer division or modulo by zero

test_d.py:8: ZeroDivisionError
____________________ ERROR at teardown of TestD.test_verify ____________________

cls = <class test_d.TestD at 0x8738fbc>

    @classmethod
    def teardown_class(cls):
>       print 1/0
E       ZeroDivisionError: integer division or modulo by zero

test_d.py:21: ZeroDivisionError
=========================== 3 error in 0.02 seconds ============================

Comments (7)

  1. holger krekel

    there are two things here i am afraid.

    Actually pytest didn't call setup_class twice, it just shows the same (recorded) setup_class exception a second time. So on one level there is a reporting issue. (on a sidenote, I want test within a failing setup_class scope to be counted so that the overall test count does not depend on which setup functions failed).

    I am also unhappy about the teardown being called after a failing setup. Unfortunately, it seems another me decided to go with someone else' suggestion in 2010, see https://bitbucket.org/hpk42/py-trunk/issue/78/pytest-fails-to-call-teardown_module-under . Wonder if changing that again to be more compatible to nose/unittest wouldn't make sense. But that's maybe another issue.

  2. shujie

    Hi it's me who created the issue, thanks for fast reply! So this is just about reporting, not a bad bug, good to have it confirmed. Regarding to teardown, I still like the way it is, even setup fails, teardown is always run. Because setup caould include multiple steps, it could pass in first a few steps but fails in the last one, teardown is necessary called to clean up status in this case.

  3. holger krekel

    If your setup fails you could catch the exception or do a "finally" and call a teardown yourself. In any case, the question how high we rate compatibility to unittest/nose. I would like to see unified behaviour on this TBH.

  4. shujie

    Yes, that could be done by finally.... which requires change for each tc. But it's fine once it's well documented, we gain a consistent behavior with other test frameworks.

  5. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.