title: py.test logging messages and test results/assertions into a single file
body: <p>I am starting to work with py.test at the moment for a new project. We are provisioning Linux servers and I need to write a script to check the setup and configuration of these servers. I thought that py.test is a good way to implement these tests and it is working quite fine until now. </p>
  
  <p>The problem I face right now is that I need a log file at the end of these tests showing some log messages for each test and the result of the test. For the log messages I use logger:</p>
  
  <pre><code>logging.basicConfig(filename='config_check.log', level=logging.INFO)
  pytest.main()
  logging.info('all done')
  </code></pre>
  
  <p>As an example test I have this:</p>
  
  <pre><code>def test_taintedKernel():
      logging.info('checking for tainted kernel')
      output = runcmd('cat /proc/sys/kernel/tainted')
      assert output == '0', 'tainted kernel found'
  </code></pre>
  
  <p>So in my logfile I would like an output like that:</p>
  
  <pre><code>INFO:root:checking for tainted kernel
  ERROR:root:tainted kernel found
  INFO:root:next test
  INFO:root:successful
  INFO:root:all done
  </code></pre>
  
  <p>But I cannot get the test results into the logfile, instead I get the standard output on stdout after the tests:</p>
  
  <pre><code>======================================= test session starts =======================================
  platform linux2 -- Python 2.6.8 -- py-1.4.22 -- pytest-2.6.0
  collected 14 items 
  
  test_basicLinux.py .............F
  
  ============================================ FAILURES =============================================
  _______________________________________ test_taintedKernel ________________________________________
  
      def test_taintedKernel():
          logging.info('checking for tainted kernel')
          output = runcmd('cat /proc/sys/kernel/tainted')
  &gt;       assert output == '0', 'tainted kernel found'
  E       AssertionError: tainted kernel found
  
  test_basicLinux.py:107: AssertionError
  =============================== 1 failed, 13 passed in 6.07 seconds ===============================
  </code></pre>
  
  <p>This may be quite confusing for the users of my script. I tried to get into logger and pytest_capturelog since it was mentioned here quite often but I am for sure doing something wrong since I just don't get it. Maybe just a lack of understanding how this really works. Hope you can give me some hints on this. Please let me know if anything is missing here.</p>
  
  <p>Thanks in advance for your help,</p>
  
  <p>Stephan</p>