main returns integer instead of sys.exit
This commit is contained in:
parent
53447e7ef5
commit
a62a5f814a
@ -446,7 +446,7 @@ def cleanup() -> None:
|
||||
exit(0)
|
||||
|
||||
|
||||
def main(sysargv=sys.argv[1:]) -> None:
|
||||
def main(sysargv=sys.argv[1:]) -> int:
|
||||
"""
|
||||
Loads and validates the config and handles the main loop
|
||||
:return: None
|
||||
@ -458,7 +458,7 @@ def main(sysargv=sys.argv[1:]) -> None:
|
||||
# A subcommand has been issued
|
||||
if hasattr(args, 'func'):
|
||||
args.func(args)
|
||||
exit(0)
|
||||
return 0
|
||||
|
||||
# Initialize logger
|
||||
logging.basicConfig(
|
||||
@ -514,7 +514,8 @@ def main(sysargv=sys.argv[1:]) -> None:
|
||||
logger.exception('Got fatal exception!')
|
||||
finally:
|
||||
cleanup()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main(sys.argv[1:])
|
||||
|
@ -25,8 +25,7 @@ def test_parse_args_backtesting(mocker):
|
||||
further argument parsing is done in test_misc.py """
|
||||
backtesting_mock = mocker.patch(
|
||||
'freqtrade.optimize.backtesting.start', MagicMock())
|
||||
with pytest.raises(SystemExit, match=r'0'):
|
||||
main.main(['backtesting'])
|
||||
main.main(['backtesting'])
|
||||
assert backtesting_mock.call_count == 1
|
||||
call_args = backtesting_mock.call_args[0][0]
|
||||
assert call_args.config == 'config.json'
|
||||
@ -40,8 +39,7 @@ def test_parse_args_backtesting(mocker):
|
||||
def test_main_start_hyperopt(mocker):
|
||||
hyperopt_mock = mocker.patch(
|
||||
'freqtrade.optimize.hyperopt.start', MagicMock())
|
||||
with pytest.raises(SystemExit, match=r'0'):
|
||||
main.main(['hyperopt'])
|
||||
main.main(['hyperopt'])
|
||||
assert hyperopt_mock.call_count == 1
|
||||
call_args = hyperopt_mock.call_args[0][0]
|
||||
assert call_args.config == 'config.json'
|
||||
@ -50,6 +48,18 @@ def test_main_start_hyperopt(mocker):
|
||||
assert call_args.func is not None
|
||||
|
||||
|
||||
# def test_main_trader(mocker):
|
||||
# mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock())
|
||||
# mocker.patch('freqtrade.misc.get_state', return_value=True)
|
||||
# mocker.patch.multiple('freqtrade.main',
|
||||
# init=MagicMock(),
|
||||
# cleanup=MagicMock(),
|
||||
# throttle=MagicMock()
|
||||
# )
|
||||
# Cant run this yet because we have an unconditional while loop in main
|
||||
# assert 0 == main.main([])
|
||||
|
||||
|
||||
def test_process_maybe_execute_buy(default_conf, mocker):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
mocker.patch('freqtrade.main.create_trade', return_value=True)
|
||||
|
Loading…
Reference in New Issue
Block a user