matkapi / postpy2

Postman collection runner library for python
Other
35 stars 15 forks source link

postpy2 File "postpy2\core.py", line 39, in __load for request in fol['item']: KeyError: 'item' #1

Closed motobeerx closed 2 years ago

motobeerx commented 3 years ago

Package name: example Link to PyPI page: https://pypi.org/project/postpy2/ Link to piwheels page: https://www.piwheels.org/project/postpy2/ Version: 0.0.6 Python version: 3.8 I am the maintainer: No More information: At using postpy2 library for working with postman, importing collection error during parsing. It simple try to get the key which does not exist. I tried to debug a little bit no success, everything is connected and I face keyerror on every step.

via pycharm I tried to run this code

from postpy2.core import PostPython runner = PostPython(r"D:\Tamm\microservice-test-automation\adp\ADP.postman_collection.json") runner.environments.load(r"D:\Tamm\microservice-test-automation\staging.postman_environment.json") runner.help() response = runner.aadc.health_pass() print(response.json()) print(response.status_code)

2020-11-30_14h56_58

the happens on 39 line. the fol['item'] is a list of dictionaries, and the key error happens because of : In: for x in self.__postman_collection['item']: print(x.keys())

Out: dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'event', 'request', 'response']) the last dictionary doesn't have key 'item'

So is there any workaround/solution ? here's the structure of my postman collection:

2020-11-30_15h10_36

And the final thing I'd like to mention is that I suppose it happens because this little guy /health - pass GET request. P.S. 1) Can this library read the global environments variables from file? 2) Can this library provide json-reports for collection run?

matprov commented 3 years ago

@motobeerx Simple workaround is to have each and every request in folders, not at collection level. Fixing this issue would be fairly simple, though, since the single request only need to be interpreted directly instead of being picked up by the for request in fol['item']:.

papadeltasierra commented 2 years ago

Can you explain why this issue was closed? I don't see any relevant changed and there is another open issue that seems to be exactly the same problem.