-
Notifications
You must be signed in to change notification settings - Fork 7
Description
The following snipped sometimes fails and sometimes passes
import unittest
class DummyVariable:
def __init__(self) -> None:
self.flag = False
def activate_flag(self):
if self.flag:
raise ValueError('Already flagged')
self.flag = True
variable = DummyVariable()
class TestVariable(unittest.TestCase):
def test_1(self):
variable.activate_flag()
def test_2(self):
variable.activate_flag()This is due to the consistent state of variable. As far as I understand, testflo executes these tests in different subprocesses based on randomization. If both tests happen to be run in the same process, the second test fails. If both tests happen to be run on different processes, the second test passes.
If I specify the -i, --isolated flag which forces testflo to run each test in its own subprocess, both tests pass all the time.
If I run this tests with python -m unittest, the second test fails all the time.
You could argue the snipped above is bad test design and I would agree but I think it is very dangerous to have such random behavior in a test setup. I think it should either fail or pass in a consistent way.