擅长:python、mysql、java
<p>Pytest还有它自己的实现,在捕获日志记录时向您显示发生了什么。如果您转到这个页面上的Live日志:<a href="https://docs.pytest.org/en/latest/logging.html" rel="nofollow noreferrer">https://docs.pytest.org/en/latest/logging.html</a>,它的解释非常好。你需要一个pytest.ini文件设置的文件:</p>
<pre><code>[pytest]
log_cli = True
</code></pre>
<p>这将使您的日志在发出时显示在终端上。然后,您可以将pytest调用的级别设置为DEBUG:</p>
<pre><code>pytest log-cli-level DEBUG
</code></pre>
<p>或者你可以在你的pytest.ini文件以及:</p>
<pre><code>[pytest]
log_cli = True
log_cli_level = DEBUG
</code></pre>
<p>其中log\u cli\u level设置显示哪些日志的级别。这种方法不会让您更改自己的代码,这很好。这当然也要求你在第一时间使用日志,但这是一个好习惯,无论如何。你知道吗</p>