title: Why is caplog.text empty, even though the function I'm testing is logging?
body: <p>I'm trying to use pytest to test if my function is logging the expected text, such as addressed <a href="https://stackoverflow.com/q/53125305/974555">this question</a> (the pyunit equivalent would be <a href="https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertLogs" rel="noreferrer">assertLogs</a>).  Following the <a href="https://docs.pytest.org/en/latest/logging.html#caplog-fixture" rel="noreferrer">pytest logging documentation</a>, I am passing the <code>caplog</code> fixture to the tester.  The documentation states:</p>
  
  <blockquote>
    <p>Lastly all the logs sent to the logger during the test run are made available on the fixture in the form of both the logging.LogRecord instances and the final log text.</p>
  </blockquote>
  
  <p>The module I'm testing is:</p>
  
  <pre class="lang-py prettyprint-override"><code>import logging
  logger = logging.getLogger(__name__)
  
  def foo():
      logger.info("Quinoa")
  </code></pre>
  
  <p>The tester is:</p>
  
  <pre class="lang-py prettyprint-override"><code>def test_foo(caplog):
      from mwe16 import foo
      foo()
      assert "Quinoa" in caplog.text
  </code></pre>
  
  <p>I would expect this test to pass.  However, running the test with <code>pytest test_mwe16.py</code> shows a test failure due to <code>caplog.text</code> being empty:</p>
  
  <pre><code>============================= test session starts ==============================
  platform linux -- Python 3.7.3, pytest-5.3.0, py-1.8.0, pluggy-0.13.0
  rootdir: /tmp
  plugins: mock-1.12.1, cov-2.8.1
  collected 1 item
  
  test_mwe16.py F                                                          [100%]
  
  =================================== FAILURES ===================================
  ___________________________________ test_foo ___________________________________
  
  caplog = &lt;_pytest.logging.LogCaptureFixture object at 0x7fa86853e8d0&gt;
  
      def test_foo(caplog):
          from mwe16 import foo
          foo()
  &gt;       assert "Quinoa" in caplog.text
  E       AssertionError: assert 'Quinoa' in ''
  E        +  where '' = &lt;_pytest.logging.LogCaptureFixture object at 0x7fa86853e8d0&gt;.text
  
  test_mwe16.py:4: AssertionError
  ============================== 1 failed in 0.06s ===============================
  </code></pre>
  
  <p>Why is <code>caplog.text</code> empty despite <code>foo()</code> sending text to a logger?  How do I use <code>pytest</code> such that <code>caplog.text</code> does capture the logged text, or otherwise verify that the text is being logged?</p>