Tenho seguinte código :
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)
Neste caso específico a instancia dataclass, ignora os parametros passados via mock e lê o sistema operacional.
Como posso contornar esta situação?