def test_destroy_config(self): initialize_config(Namespace()) conf = config() with self.assertRaises(AttributeError): conf.tmp destroy_config() parser2 = ArgumentParser() parser2.add_argument("--tmp5", type=str) parser2.add_argument("--tmp6", type=int) cli_args3 = ["--tmp5", "val5", "--tmp6", "6"] args3 = parser2.parse_args(cli_args3) initialize_config(args3) conf3 = config() self.assertNotEqual(conf3, conf) self.assertEqual(conf3.tmp5, "val5") self.assertEqual(conf3.tmp6, 6) with self.assertRaises(AttributeError): config().tmp1 with self.assertRaises(AttributeError): config().tmp2
def fake_config(**kwargs): _fake_config(**kwargs) try: yield finally: destroy_config()
def _fake_config(**kwargs): destroy_config() namespace = Namespace() for k, v in kwargs.items(): setattr(namespace, k, v) initialize_config(namespace)
def setUp(self) -> None: destroy_config()