How can I see log messages when unit testing in PyCharm?

后端 未结 6 1286
忘掉有多难
忘掉有多难 2021-02-05 06:35

I\'m sure this is a simple fix, but I\'d like to view log messages in the PyCharm console while running a unit test. The modules I\'m testing have their own loggers, an

6条回答
  •  余生分开走
    2021-02-05 06:56

    I experienced this problem all of a sudden after updating Pycharm. I had been running my tests with the Unittest runner, and all of a sudden Pycharm decided the default should be the pytest runner. When I changed the default test runner back to Unittest the logs appeared as I expected they would.
    You can change the default test runner in Project Settings/Preferences >> Tools >> Python Integrated Tools

    I assume adding the -nologcapture flag as noted in other answers probably would have worked in my case as well, but I prefer a solution that's exposed by the IDE rather than a manual override.

    BTW choosing Unittest also solves an additional error that I got once when trying to run tests - No module named 'nose'

提交回复
热议问题