def test_cli_from_bool_flag(default, monkeypatch): def factory(flag: bool = default): pass monkeypatch.setattr(sys, 'argv', ['python', '--flag']) monkeypatch.setattr(test_pkg, 'mocked_factory', factory, raising=False) parser = CustomParser() with parser: pass parser.process_factory_dotted_path('test_pkg.mocked_factory') actions = {a.dest: a for a in parser._actions} # default should match with function's signature assert actions['flag'].default is default # passing the flag should flip the value assert actions['flag'].const is not default
def test_cli_from_param(default, monkeypatch): def factory(param=default): return param monkeypatch.setattr(sys, 'argv', ['python', '--param', 'value']) monkeypatch.setattr(test_pkg, 'mocked_factory', factory, raising=False) parser = CustomParser() with parser: pass returned, args = parser.process_factory_dotted_path( 'test_pkg.mocked_factory') actions = {a.dest: a for a in parser._actions} assert actions['param'].default == default assert args.param == 'value' assert returned == 'value'