How to use logging, pytest fixture and capsys?

后端 未结 3 577
灰色年华
灰色年华 2021-01-04 19:14

I am trying to unit-test some algorithm that uses logging library.

I have a fixture that creates a logger.

In my 1st test case, I do not use

3条回答
  •  时光取名叫无心
    2021-01-04 20:07

    I'm guessing the logger gets created (via the fixture) before the capsys fixture is set up.

    Some ideas:

    • Use the pytest-catchlog plugin
    • Maybe reverse logger, capsys
    • Make logger request the capsys fixture
    • Use capfd which is more lowlevel capturing without altering sys

提交回复
热议问题