vendredi 24 juin 2016

How to generate python coverage report for methods only


We've built a framework to test northbound apis of our project, based on pytest. And now we want to have a coverage report about how many apis are tested(basically, are called) by running the test scripts we have. We already have a well-defined client manager, which makes every api as a python method. For example, say we have an api GET /user,then we will have a method get_user which sends the actual request to server. We are now using python-coverage (actually pytest-cov but it's the same thing) which will give us a report of code coverage, and based on that, we will have some sort of concept about how many apis are called. However, it's not accurate and clear enough. So the key question is, what's the best way in python/pytest to have a list about the methods (of a specific object, in this case) were called during a test run. I will give an example to illustrate the question. class Client(object): def __init__(self): pass def get_user(self, user): pass def post_user(self, user): pass def delete_user(self, user): pass def test_get_user(): Client().get_user("user") def test_post_user(): Client().post_user("user") After running the two tests, how can I get a report saying that get_user and post_user was called and delete_user was not called during last run. One possible solution is, since running tests with coverage.py will give us enough information about line numbers and files being executed, maybe I can analyze what I need from there. Another possible solution is to track which method is called in Client I defined, it should work but I am not willing to change the auto generated code since our clients are auto generated by Swagger. Is there a more decent way to achieve my goal?

Aucun commentaire:

Enregistrer un commentaire