unittest-xml-reporting
unittest-xml-reporting copied to clipboard
try to fix error where modules writing directly to sys.stdout.buffer blow up
Handle error case (due to using python-subunit + unittest-xml-reporting) where sys.stdout has no buffer attribute, causing a failure and hang in subunit:
protocol = TestProtocolServer(result, self._passthrough, self._forward) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.11/site-packages/subunit/init.py", line 510, in init stream = sys.stdout.buffer ^^^^^^^^^^^^^^^^^ AttributeError: '_DuplicateWriter' object has no attribute 'buffer'
This is due to python-subunit setting "stream = sys.stdout.buffer", but _DuplicateWriter() has no buffer attriibute. I tried handling this in a PR in python-subunit module, but they weren't really having it: https://github.com/testing-cabal/subunit/pull/56
This works from what I can tell and doesn't seem to have negative side effects... I also fixed tox.ini to work properly with Tox4, as it was not as-is.
tests seem to have some sort of basic failure blocking the run, not having to do with my changes... ============================= test session starts ============================== platform darwin -- Python 3.11.0, pytest-7.2.1, pluggy-1.0.0 cachedir: .tox/pytest/.pytest_cache rootdir: /Users/nelschantarotwong/Downloads/unittest-xml-reporting-master, configfile: tox.ini, testpaths: tests collected 89 items
tests/builder_test.py ........................ [ 26%] tests/django_test.py ....... [ 34%] tests/testsuite.py .F...........F......x................................ [ 94%] ..... [100%]
=================================== FAILURES =================================== _____________ XMLTestRunnerTestCase.test_basic_unittest_constructs _____________
self = <tests.testsuite.XMLTestRunnerTestCase testMethod=test_basic_unittest_constructs>
def test_basic_unittest_constructs(self):
suite = unittest.TestSuite()
suite.addTest(self.DummyTest('test_pass'))
suite.addTest(self.DummyTest('test_skip'))
suite.addTest(self.DummyTest('test_fail'))
suite.addTest(self.DummyTest('test_expected_failure'))
suite.addTest(self.DummyTest('test_unexpected_success'))
suite.addTest(self.DummyTest('test_error'))
self._test_xmlrunner(suite)
tests/testsuite.py:255:
tests/testsuite.py:240: in _test_xmlrunner runner.run(suite) xmlrunner/runner.py:72: in run result.printErrors() E AttributeError: 'tuple' object has no attribute 'shortDescription' ________________ XMLTestRunnerTestCase.test_unexpected_success _________________
self = <tests.testsuite.XMLTestRunnerTestCase testMethod=test_unexpected_success>
def test_unexpected_success(self):
suite = unittest.TestSuite()
suite.addTest(self.DummyTest('test_unexpected_success'))
outdir = BytesIO()
self._test_xmlrunner(suite, outdir=outdir)
tests/testsuite.py:300:
tests/testsuite.py:240: in _test_xmlrunner runner.run(suite) xmlrunner/runner.py:72: in run result.printErrors() E AttributeError: 'tuple' object has no attribute 'shortDescription' =============================== warnings summary =============================== .tox/pytest/lib/python3.11/site-packages/django/http/request.py:1 /Users/nelschantarotwong/Downloads/unittest-xml-reporting-master/.tox/pytest/lib/python3.11/site-packages/django/http/request.py:1: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13 import cgi
.tox/pytest/lib/python3.11/site-packages/django/utils/encoding.py:266 /Users/nelschantarotwong/Downloads/unittest-xml-reporting-master/.tox/pytest/lib/python3.11/site-packages/django/utils/encoding.py:266: DeprecationWarning: Use setlocale(), getencoding() and getlocale() instead encoding = locale.getdefaultlocale()[1] or 'ascii'
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =========================== short test summary info ============================ FAILED tests/testsuite.py::XMLTestRunnerTestCase::test_basic_unittest_constructs - AttributeError: 'tuple' object has no attribute 'shortDescription' FAILED tests/testsuite.py::XMLTestRunnerTestCase::test_unexpected_success - AttributeError: 'tuple' object has no attribute 'shortDescription' ============= 2 failed, 86 passed, 1 xfailed, 2 warnings in 0.58s ============== pytest: exit 1 (0.88 seconds) /Users/nelschantarotwong/Downloads/unittest-xml-reporting-master> pytest pid=73642 .pkg: _exit tests> python /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta legacy pytest: FAIL code 1 (3.18=setup[2.31]+cmd[0.88] seconds) evaluation failed :( (3.28 seconds)
Wondering if this is due to being on python 3.11. Tox test run seems to use this system version even if I setup my PyCharm virtual env to use a lower version.