AttributeError: ‘generator’ object has no attribute ‘append’

Total
1
Shares

I used to run this code as a unittest but suddenly it’s not working

code:

    import requests
    import pytest
  
    class TestSample:
        url = 'https://something/apiname'
        @pytest.fixture()
        def post_request(self, data):
            url = self.url + '/1'
            res = requests.post(url, headers={"Content-Type": "application/json"},json=data)
            yield res
    
        @pytest.mark.parametrize("data,result",
                    [( {"ids": ["524234", "12341", "97555"]},200))]
        def test_post_sample_data(self, data, result, post_request):
             rs = post_request
             assert rs.status_code == result

Error:

platform win32 -- Python 3.6.4, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
plugins: hypothesis-5.37.4, cases-2.3.0
test_selectsample.py:None (test_selectsample.py)
....AppDataLocalProgramsPythonPython36libsite-packagespluggyhooks.py:286: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
....AppDataLocalProgramsPythonPython36libsite-packagespluggymanager.py:93: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
....AppDataLocalProgramsPythonPython36libsite-packagespluggymanager.py:87: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
....AppDataLocalProgramsPythonPython36libsite-packages_pytestpython.py:249: in pytest_pycollect_makeitem
    initialnames, node, ignore_args=self._get_direct_parametrize_args(node)
....AppDataLocalProgramsPythonPython36libsite-packagespytest_casesplugin.py:614: in getfixtureclosure
    _init_fixnames, super_closure, arg2fixturedefs = create_super_closure(fm, parentnode, fixturenames, ignore_args)
....AppDataLocalProgramsPythonPython36libsite-packagespytest_casesplugin.py:668: in create_super_closure
    _merge(sorted_fixturenames, _init_fixnames)
....AppDataLocalProgramsPythonPython36libsite-packagespytest_casesplugin.py:655: in _merge
    into_list.append(item)
E   AttributeError: 'generator' object has no attribute 'append'
collected 0 items / 1 error

=================================== ERRORS ====================================

_____________________ ERROR collecting test_selectids.py ______________________
....AppDataLocalProgramsPythonPython36libsite-packagespluggyhooks.py:286: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
....AppDataLocalProgramsPythonPython36libsite-packagespluggymanager.py:93: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
    res = list(collector._genfunctions(name, obj))
....AppDataLocalProgramsPythonPython36libsite-packages_pytestpython.py:458: in _genfunctions
    initialnames, node, ignore_args=self._get_direct_parametrize_args(node)
....AppDataLocalProgramsPythonPython36libsite-packagespytest_casesplugin.py:614: in getfixtureclosure
    _init_fixnames, super_closure, arg2fixturedefs = create_super_closure(fm, parentnode, fixturenames, ignore_args)
....AppDataLocalProgramsPythonPython36libsite-packagespytest_casesplugin.py:668: in create_super_closure
    _merge(sorted_fixturenames, _init_fixnames)
....AppDataLocalProgramsPythonPython36libsite-packagespytest_casesplugin.py:655: in _merge
    into_list.append(item)
E   AttributeError: 'generator' object has no attribute 'append'
=========================== short test summary info ===========================
ERROR test_selectsample.py::TestSample - AttributeError: 'generator' object ha...
!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
============================== 1 error in 0.35s ===============================
Process finished with exit code 0
Assertion failed
Assertion failed

Any idea what may be causing that? How can I prevent it?
Thanks in advance


Solution

This issue has been fixed by changing the version of the interpreter. I changed python3.6 to 3.8 and problem solved ! Hope this post would be useful for someone

Leave a Reply

Your email address will not be published. Required fields are marked *