Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for attachments to test execution (#3982)
* Add support for attachments to test execution By default in CI and with tox locally we run all the tests in parallel. However, this makes things like printing to stdout, warnings on stderr, or logging during tests difficult to deal with. This is because we'll have multiple writers to the output streams simultaneously and no way to figure out which text goes to which test. Luckily stestr and the subunit protocl it uses internally has a method for adding attachments to test results to handle this kind of case. Using this each output stream is associated with the test which generated it and will get displayed as such. The only issue with this is that the stdlib unittest doesn't know how to write attachments to it's result stream. There is a unittest extension library testtools[1] that provides this functionality in a strictly compatible manner with unittest, however the current state of the library needs some work before it can work well with more modern features of stdlib unittest from python>3.5 so we either have to change the tests to not use these features or come up with an alternative solution for test attachments. This commit ports the necessary result streaming functionality from testtools into the QiskitTestCase base test class and then sets up the appropriate fixtures to attach output streams from each test. This works around the current limitation with testtools (I'm slowly working on fixing this in testtools) but still provides the functionality. When testtools is at the point it can be a drop in replacement for unittest as terra is using it we can drop this code. As part of this change all the test classes that define a setUp have a missing super() call added. This framework does not work without setUp in the base class being defined since that's what is used to setup the stream capture. Moving forward the base test class actually enforces that super() is called, otherwise the tests will fail. [1] https://github.com/testing-cabal/testtools * Fix lint * Update contributing doc * Fix copy paste error * Add missing super calls from new tests * Add missing super() calls and fix skip message * Fix lint Co-authored-by: Luciano Bello <[email protected]>
- Loading branch information