Skip to content

setUpClass errors, but setUp fails on unittest.TestCase #11604

Open
@tucked

Description

@tucked

When a fixture fails, Pytest reports an error:

import pytest


@pytest.fixture
def fail():
    assert False


def test_pass(fail):
    pass
============================= test session starts ==============================
platform linux -- Python 3.9.18, pytest-7.4.3, pluggy-1.3.0
rootdir: /tmp/tmp.CAhPLzhZ0P
collected 1 item

test_pytest.py E                                                         [100%]

==================================== ERRORS ====================================
_________________________ ERROR at setup of test_pass __________________________

    @pytest.fixture
    def fail():
>       assert False
E       assert False

test_pytest.py:6: AssertionError
=========================== short test summary info ============================
ERROR test_pytest.py::test_pass - assert False
=============================== 1 error in 0.03s ===============================

The same thing happens when setUpClass fails on a unittest.TestCase:

import unittest


class Test(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        assert False

    def test_sscce(self):
        assert True
============================= test session starts ==============================
platform linux -- Python 3.9.18, pytest-7.4.3, pluggy-1.3.0
rootdir: /tmp/tmp.CAhPLzhZ0P
collected 1 item

test_unittest.py E                                                       [100%]

==================================== ERRORS ====================================
______________________ ERROR at setup of Test.test_sscce _______________________

cls = <class 'test_unittest.Test'>

    @classmethod
    def setUpClass(cls):
>       assert False
E       assert False

test_unittest.py:7: AssertionError
=========================== short test summary info ============================
ERROR test_unittest.py::Test::test_sscce - assert False
=============================== 1 error in 0.04s ===============================

However, if setUp fails, Pytest reports a failure:

import unittest


class Test(unittest.TestCase):
    def setUp(self):
        assert False

    def test_sscce(self):
        assert True
============================= test session starts ==============================
platform linux -- Python 3.9.18, pytest-7.4.3, pluggy-1.3.0
rootdir: /tmp/tmp.CAhPLzhZ0P
collected 1 item

test_unittest.py F                                                       [100%]

=================================== FAILURES ===================================
_______________________________ Test.test_sscce ________________________________

self = <test_unittest.Test testMethod=test_sscce>

    def setUp(self):
>       assert False
E       assert False

test_unittest.py:6: AssertionError
=========================== short test summary info ============================
FAILED test_unittest.py::Test::test_sscce - assert False
============================== 1 failed in 0.03s ===============================

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: unittestrelated to the unittest integration builtin plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions