Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace TextTestResult with TestResult for Py3.11 #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kangie
Copy link

@Kangie Kangie commented Jun 6, 2022

Long story short, unittest >= py3.11 returns test1 (tests.MyTest.test1) ... ok instead of test1 (tests.MyTest) ... ok

This PR replaces unittest.TextTestResult with unittest.TestResult which, while not reporting to stdout, still passes the existing metadata check (i.e. expected passes match and expected failures match) and serves to illustrate usage of unittest with manuel.

I had a bit of a fiddle with this one but couldn't find a way to do a conditional, theoretically something similar to the below would preserve existing behaviour.

if sys.version_info() >= (3,11):
    test1 (tests.MyTest.test1) ... ok
    test2 (tests.MyTest.test2) ... ok
    test3 (tests.MyTest.test3) ... FAIL
else:
    test1 (tests.MyTest) ... ok
    test2 (tests.MyTest) ... ok
    test3 (tests.MyTest) ... FAIL

If there is a syntax for this that I've missed, please let me know!

Fixes: #30

@benji-york
Copy link
Owner

Thanks for looking into this. I appreciate it!

I do slightly prefer seeing the passes and failures reported in the test, but it's not a huge deal.

If there is a syntax for this that I've missed, please let me know!

There is one possibility if you're interested in looking into it: output checkers. They are introduced in the doctest section of the docs: https://pythonhosted.org/manuel/#doctests

@Kangie
Copy link
Author

Kangie commented Jun 8, 2022

I'll take a look, should have some time this weekend.

@dotlambda
Copy link

Any updates?

@Kangie
Copy link
Author

Kangie commented Feb 23, 2023

June 2022 was a while ago, work/life got hectic.

I'll read up on the doctests stuff maybe next weekend and see if I can come up with a solution if something hasn't already been committed in the meantime. Unfortunately I may just be busy through May at this point!

@benji-york
Copy link
Owner

I think this issue has been superseded by recent work.

@kloczek
Copy link

kloczek commented May 26, 2024

Tested this PR and pytest fails form me in src/manuel/testing.py::TestCase

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-manuel-1.12.4-8.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-manuel-1.12.4-8.fc37.x86_64/usr/lib/python3.10/site-packages
+ /usr/bin/pytest -ra -m 'not network' src/manuel/testcase.py src/manuel/testing.py src/manuel/tests.py
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.10.14, pytest-8.2.1, pluggy-1.5.0
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/tkloczko/rpmbuild/BUILD/manuel-1.12.4
plugins: hypothesis-6.100.0, benchmark-4.0.0, mock-3.14.0, timeout-2.3.1, twisted-1.14.1, tornasync-0.6.0.post2, trio-0.8.0, anyio-4.3.0, asyncio-0.23.7
asyncio: mode=strict
collected 1 item / 1 error

========================================================================================== ERRORS ===========================================================================================
__________________________________________________________________________ ERROR collecting src/manuel/testing.py ___________________________________________________________________________
/usr/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
/usr/lib/python3.10/site-packages/_pytest/runner.py:389: in collect
    return list(collector.collect())
/usr/lib/python3.10/site-packages/_pytest/unittest.py:90: in collect
    self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid)
/usr/lib/python3.10/site-packages/_pytest/unittest.py:75: in newinstance
    return self.obj("runTest")
E   TypeError: TestCase.__init__() missing 2 required positional arguments: 'regions' and 'globs'
===================================================================================== warnings summary ======================================================================================
src/manuel/testing.py:15
  /home/tkloczko/rpmbuild/BUILD/manuel-1.12.4/src/manuel/testing.py:15: PytestCollectionWarning: cannot collect test class 'TestCaseMarker' because it has a __init__ constructor (from: src/manuel/testing.py)
    class TestCaseMarker:

src/manuel/testing.py:200
  /home/tkloczko/rpmbuild/BUILD/manuel-1.12.4/src/manuel/testing.py:200: PytestCollectionWarning: cannot collect test class 'TestFactory' because it has a __init__ constructor (from: src/manuel/testing.py)
    class TestFactory:

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ==================================================================================
ERROR src/manuel/testing.py::TestCase - TypeError: TestCase.__init__() missing 2 required positional arguments: 'regions' and 'globs'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=============================================================================== 2 warnings, 1 error in 0.25s ================================================================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test failures with Python 3.11.0b1
4 participants