Skip to content

pytest 8.2.0 calls @propertys during unittest collection #12446

Closed
@grzegorzmiazga

Description

@grzegorzmiazga

Since 8.2.0 and changes to unittest collecting pytests behaves now slightly differently. If there is @Property defined in unittest class it is called during tests collection. This leads to some absurd behaviour with each property being collected twice. Attached example takes 20s to collect instead of 0.01s

import unittest
from time import sleep

class TestClass(unittest.TestCase):

    @property
    def variable(self):
        print('My collection sleep')
        sleep(10)


class MyTest(TestClass):
    def test_simple(self):
        assert True

pip list output:

pip list
Package                   Version
------------------------- ---------
attrs                     23.2.0
cffi                      1.16.0
cryptography              42.0.8
exceptiongroup            1.2.1
iniconfig                 2.0.0
jsonschema                4.22.0
jsonschema-specifications 2023.12.1
packaging                 24.1
pip                       22.0.4
pluggy                    1.5.0
pycparser                 2.22
pyOpenSSL                 24.1.0
pytest                    8.2.2
referencing               0.35.1
rpds-py                   0.18.1
setuptools                58.1.0
tomli                     2.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: unittestrelated to the unittest integration builtin plugintype: performanceperformance or memory problem/improvementtype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions