kniklas / get-fx

Get FX is tool to download average FX rates from National Bank of Poland (NBP)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot apply patch.object for parse_args() method

kniklas opened this issue · comments

It was planned to apply pytest patch.object on ArgumentParser.parse_args() method to mock command line arguments - by passing custom command line arguments (in case of test: test_USD_currency: it is ['USD'] parameter).

But this does not work, it returns below error. It appears that passed ['USD'] argument via parse.args is expected to be self object of this method,

platform darwin -- Python 3.8.5, pytest-6.1.0, py-1.9.0, pluggy-0.13.1
rootdir: /Users/kamil/git/get-fx
plugins: cov-2.10.1
collected 18 items

getfxparser_test.py .F...                                                                             [ 27%]
getfx/getfx_test.py ....                                                                              [ 50%]
getfxnbp/getfxnbp_test.py .........                                                                   [100%]

================================================= FAILURES ==================================================
_____________________________________________ test_USD_currency _____________________________________________

    def test_USD_currency():
        test_args = ["USD"]
        #  import wdb; wdb.set_trace()
        with patch.object(ArgumentParser, 'parse_args',
>                         return_value=ArgumentParser.parse_args(test_args)):

getfxparser_test.py:21:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = ['USD'], args = None, namespace = None

    def parse_args(self, args=None, namespace=None):
>       args, argv = self.parse_known_args(args, namespace)
E       AttributeError: 'list' object has no attribute 'parse_known_args'

../../.pyenv/versions/3.8.5/lib/python3.8/argparse.py:1768: AttributeError
========================================== short test summary info ==========================================
FAILED getfxparser_test.py::test_USD_currency - AttributeError: 'list' object has no attribute 'parse_know...

See commit for details: 17ac2c5

Fixed in commit: efb1495