Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

setUpClass method executed once per test with multiple workers #127

Open
rafoid opened this issue Mar 23, 2023 · 0 comments
Open

setUpClass method executed once per test with multiple workers #127

rafoid opened this issue Mar 23, 2023 · 0 comments

Comments

@rafoid
Copy link

rafoid commented Mar 23, 2023

I have the following test:

import unittest

class SomeTest(unittest.TestCase):

    def test_unit1(self):
        pass

    def test_unit2(self):
        pass

    def test_unit3(self):
        pass

    def test_unit4(self):
        pass

    def test_unit5(self):
        pass

    @classmethod
    def setUpClass(cls):
        with open('/tmp/abc.txt', 'a') as f :
            f.write('######\n')

This test class when ran with multiple workers runs setUpClass() five times, instead of once! I run it with the following command:

pytest --workers 10 myTests.py

Then when checking the text file I see that it was ran 5 times:

 cat /tmp/abc.txt 
######
######
######
######
######

here is my env:

=========================== test session starts ===========================
platform linux -- Python 3.6.8, pytest-7.0.1, pluggy-1.0.0
rootdir: <omitted>, configfile: pytest.ini
plugins: parallel-0.1.1
collected 5 items                                                         
pytest-parallel: 10 workers (processes), 1 test per worker (thread)
..........
============================ 5 passed in 0.09s ============================
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant