4

I am trying to add a custom display of data of the test runs that occured during my pytest execution. Instead of something like :

--------------- 3 passed in 30 seconds ----------------

at the end of the test, I would want to display a tabular representaion of the test runs with my own metrics. I have the metrics recorded in a variable which is in JSON format.

How could I show this JSON at the end of pytest execution in tabular format something like this:

--------------- 3 passed in 30 seconds ----------------

Test Name     Stages      Date_Time     Some_Paramter_1    Some_Parameter_2

  A

  B

  C

All of the data required for the above (the test Name, stages, parameters) I have recorded in a JSON object.

Thanks,

I have tried some reporting tools, but they don't exactly give me the kind of custom results I want. Like Tesults.

Steve-o169
  • 2,066
  • 1
  • 12
  • 21
ArYad
  • 125
  • 6
  • For displaying custom data in `pytest` at different stages, check out [this answer](https://stackoverflow.com/a/53640991/2650249). For printing tabular data, you might get some ideas from the answers to [Printing Lists as Tabular Data](https://stackoverflow.com/q/9535954/2650249). – hoefling Jul 02 '19 at 19:09
  • Most of the hooks given here may be subjected to changes since it's imported by `_pytest.runner`. So, it's highly risky to use these. – ArYad Jul 02 '19 at 20:10
  • [All of these hooks are listed in the official API docs](https://docs.pytest.org/en/latest/reference.html#hooks) as they are designed by the `pytest` devs to be used and reimplemented. – hoefling Jul 02 '19 at 20:33
  • Ok. I am using `pytest_unconfigure(config)` to basically print my custom result but I have a fixture that's setting the values inside the data object and I want to use that inside the `pytest_unconfigure`. I am struggling to use it inside this. Any idea on how to access that object in this ? – ArYad Jul 02 '19 at 21:21
  • You can use `request.config` to attach the object in fixture, then reference the object via `config` in hook. – hoefling Jul 02 '19 at 21:25
  • Thanks @hoefling. I was able to do it. – ArYad Jul 02 '19 at 21:46

0 Answers0