0
I have following code :
import unittest
import unittest.mock as mock
from dataclasses import dataclass
@dataclass
class Config:
system: str = platform.system().lower()
class TestConfig(unittest.TestCase):
def test_Config_linux(self):
system = 'linux'
with mock.patch('platform.system', return_value=system), \
mock.patch.dict(os.environ, {'INCOLUMEPY_SYSTEM': system}):
op_cfg = configure.Config()
self.assertEqual(system, op_cfg.system)
def test_Config_win(self):
system = 'windows'
with mock.patch('platform.system', return_value=system), \
mock.patch.dict(os.environ, {'INCOLUMEPY_SYSTEM': system}):
config()
op_cfg = configure.Config()
self.assertEqual(system, op_cfg.system)
def test_Config_mac(self):
system = 'mac'
with mock.patch('platform.system', return_value=system), \
mock.patch.dict(os.environ, {'INCOLUMEPY_SYSTEM': system}):
op_cfg = configure.Config()
self.assertEqual(system, op_cfg.system)
In this specific case the instance dataclass ignores the parameters passed via mock and reads the operating system.
How can I get around this situation?