cyberdelia / metrology

A library to easily measure what's going on in your python.
https://metrology.readthedocs.org
MIT License
309 stars 25 forks source link

Fixed running unittests with py.test #41

Closed ghost closed 4 years ago

ghost commented 4 years ago

Currently Travis CI builds are failing while running pytest with the following error:

=================================== FAILURES ===================================

________________________ LoggerReporterTest.test_write _________________________

self = <test_logger.LoggerReporterTest testMethod=test_write>

    def test_write(self):

        self.reporter.write()

>       self.assertTrue("median=" in self.output.getvalue())

E       AssertionError: False is not true

tests/reporter/test_logger.py:32: AssertionError

Is's happening because self.output is not successfully set as output stream with logging.basicConfig since logging is already initialized by pytest and basicConfig isn't overwriting the settings.

This could be fixed in several ways: pytest specific by using the log capture feature and otherwise by adding a Stream-Handler manually to logging. While the former would create an explicit dependency to pytest, the latter would be more convoluted.

So this pull request goes the least intrusive route and just disables the log capture feature of pytest while running the unittests through tox.

cyberdelia commented 4 years ago

Thank you!