kevlened / pytest-parallel

A pytest plugin for parallel and concurrent testing
https://github.com/browsertron/pytest-parallel/issues/104#issuecomment-1293941066
MIT License
313 stars 59 forks source link

setUpClass method executed once per test with multiple workers #127

Open rafoid opened 1 year ago

rafoid commented 1 year ago

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 ============================