In which py.test callout can I find both 'item' and 'report' data?

后端 未结 2 1987
遥遥无期
遥遥无期 2021-02-09 08:28

pytest_runtest_makereport() gets two arguments, item and call. From item, I can find the funcarg I created for this test, and from call, I can find the exception info (if any):

2条回答
  •  不思量自难忘°
    2021-02-09 08:35

    There is a little undocumented somewhat unofficial method with which hook implementations can interact with other hook implementations, for example to post-process their result. In your concrete case you might do something like:

    @pytest.mark.tryfirst
    def pytest_runtest_makereport(item, call, __multicall__):
        rep = __multicall__.execute()
        # your code follows and you can use rep.passed etc.
        return rep
    

    Notes:

    • a hook call will usually call multiple hook implementations
    • the "tryfirst" marker instructs the hook call to have your implementation be invoked early
    • the multicall parameter represents the ongoing hook call and can be used to call the remaining hook implementations and then
      use their result for further processing
    • you need to return "rep" here because you shadow the "real" creation

    The multicall API is very seldomly really and i suspect there could be solutions for your use case that don't require it.

    HTH, Holger

提交回复
热议问题