title: pytest: How to show messages from logging.debug in the function under test
body: <pre class="lang-py prettyprint-override"><code>''' func.py '''
  import logging
  
  def func():
      ''' func '''
      logging.basicConfig(
          format=&quot;\t %(filename)s&quot;
          &quot; %(funcName)s&quot;
          &quot;-ln%(lineno)d&quot;
          &quot; %(levelname)s \n%(message)s&quot;,
          level=logging.DEBUG,
          # stream=sys.stdout,
      )
      logger = logging.getLogger()
      logger.info(&quot; &gt;&gt;&gt; logger func info&quot;)
      logger.warning(&quot; &gt;&gt;&gt; logger func warning&quot;)
      print(&quot; &gt;&gt;&gt; print func info&quot;)
  
  
  def test_func():
      ''' test func '''
      # caplog.set_level(logging.DEBUG)
      func()
  
  
  if __name__ == &quot;__main__&quot;:
      test_func()
  </code></pre>
  <p>Suppose I save the code above as func.py. When I run</p>
  <pre><code>pytest -s func.py
  </code></pre>
  <p>I obtain</p>
  <pre><code>&quot; &gt;&gt;&gt; print func info&quot;.
  </code></pre>
  <p>How can I obtain</p>
  <pre><code>&quot; &gt;&gt;&gt; logger func info&quot; 
  </code></pre>
  <p>and</p>
  <p>&quot; &gt;&gt;&gt; logger func warning&quot;</p>
  <p>when I run</p>
  <pre><code>pytest -s func.py
  </code></pre>
  <p>I wish I can do this for the following reason. I normally insert logging.debug/info etc in the my codes. Sometimes, I want to see messages emitted by  logging.debug/info when I run pytest. I searched the net for quite a while but cant find a way. Thanks in advance for any help.</p>