Skip to content
This repository has been archived by the owner on Nov 25, 2023. It is now read-only.

support pytest #16

Open
kloczek opened this issue Jun 22, 2021 · 6 comments
Open

support pytest #16

kloczek opened this issue Jun 22, 2021 · 6 comments

Comments

@kloczek
Copy link
Contributor

kloczek commented Jun 22, 2021

Just normal build, install and test cycle used on building package from non-root account:

  • "setup.py build"
  • "setup.py install --root </install/prefix>"
  • "pytest with PYTHONPATH pointing to setearch and sitelib inside </install/prefix>
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-traceback2-1.4.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-traceback2-1.4.0-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ PYTHONDONTWRITEBYTECODE=1
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.9, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
benchmark: 3.4.1 (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/traceback2-1.4.0
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, expect-1.1.0, httpbin-1.0.0, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, freezegun-0.4.2, case-1.5.3, isort-1.3.0, aspectlib-1.5.2, asyncio-0.15.1, toolbox-0.5, xprocess-0.17.1, aiohttp-0.3.0, checkdocs-2.7.0, mock-3.6.1, rerunfailures-9.1.1, requests-mock-1.9.3, cov-2.12.1, pyfakefs-4.5.0, cases-3.6.1, flaky-3.7.0, hypothesis-6.14.0, benchmark-3.4.1, xdist-2.3.0, Faker-8.8.1
collected 49 items

. .                                                                                                                                                                  [  2%]
traceback2/tests/test_traceback.py ...............F...........F.........ss........                                                                                   [100%]

================================================================================= FAILURES =================================================================================
_______________________________________________________________ PyExcReportingTests.test_context_suppression _______________________________________________________________
'NoneType' object is not iterable

During handling of the above exception, another exception occurred:
NOTE: Incompatible Exception Representation, displaying natively:

testtools.testresult.real._StringException: Traceback (most recent call last):
  File "/home/tkloczko/rpmbuild/BUILD/traceback2-1.4.0/traceback2/tests/test_traceback.py", line 419, in test_context_suppression
    self.assertThat(lines, DocTestMatches("""\
  File "/usr/lib/python3.8/site-packages/testtools/testcase.py", line 478, in assertThat
    raise mismatch_error
testtools.matchers._impl.MismatchError: Expected:
    Traceback (most recent call last):
      File "...traceback2/tests/test_traceback.py", line ..., in test_context_suppression
        raise_from(ZeroDivisionError, None)
      File "<string>", line 2, in raise_from
    ZeroDivisionError
Got:
    Traceback (most recent call last):
      File "/home/tkloczko/rpmbuild/BUILD/traceback2-1.4.0/traceback2/tests/test_traceback.py", line 414, in test_context_suppression
        raise_from(ZeroDivisionError, None)
      File "<string>", line 3, in raise_from
    ZeroDivisionError
_______________________________________________________________________ TestStack.test_format_locals _______________________________________________________________________

self = <traceback2.tests.test_traceback.TestStack testMethod=test_format_locals>

    def test_format_locals(self):
        def some_inner(k, v):
            a = 1
            b = 2
            return traceback.StackSummary.extract(
                traceback.walk_stack(None), capture_locals=True, limit=1)
        s = some_inner(3, 4)
>       self.assertEqual(
            ['  File "' + FNAME + '", line 651, '
             'in some_inner\n'
             '    traceback.walk_stack(None), capture_locals=True, limit=1)\n'
             '    a = 1\n'
             '    b = 2\n'
             '    k = 3\n'
             '    v = 4\n'
            ], s.format())
E       AssertionError: Lists differ: ['  F[91 chars]ne 651, in some_inner\n    traceback.walk_stac[81 chars]4\n'] != ['  F[91 chars]ne 650, in some_inner\n    return traceback.St[62 chars]4\n']
E
E       First differing element 0:
E         File "/home/tkloczko/rpmbuild/BUILD/traceback2-1.4.0/traceback2/tests/test_traceback.py", line 651, in some_inner
E           traceback.walk_stack(None), capture_locals=True, limit=1)
E           a = 1
E           b = 2
E           k = 3
E           v = 4
E
E         File "/home/tkloczko/rpmbuild/BUILD/traceback2-1.4.0/traceback2/tests/test_traceback.py", line 650, in some_inner
E           return traceback.StackSummary.extract(
E           a = 1
E           b = 2
E           k = 3
E           v = 4
E
E
E         ['  File '
E          '"/home/tkloczko/rpmbuild/BUILD/traceback2-1.4.0/traceback2/tests/test_traceback.py", '
E       -  'line 651, in some_inner\n'
E       ?          ^
E
E       +  'line 650, in some_inner\n'
E       ?          ^
E
E       -  '    traceback.walk_stack(None), capture_locals=True, limit=1)\n'
E       +  '    return traceback.StackSummary.extract(\n'
E          '    a = 1\n'
E          '    b = 2\n'
E          '    k = 3\n'
E          '    v = 4\n']

traceback2/tests/test_traceback.py:653: AssertionError
========================================================================= short test summary info ==========================================================================
SKIPPED [1] traceback2/tests/test_traceback.py:869: Applies to 2.x only.
SKIPPED [1] traceback2/tests/test_traceback.py:837: Applies to 2.x only.
FAILED traceback2/tests/test_traceback.py::PyExcReportingTests::test_context_suppression
FAILED traceback2/tests/test_traceback.py::TestStack::test_format_locals - AssertionError: Lists differ: ['  F[91 chars]ne 651, in some_inner\n    traceback.walk_stac[81...
================================================================= 2 failed, 44 passed, 2 skipped in 8.50s ==================================================================
@kloczek
Copy link
Contributor Author

kloczek commented Dec 26, 2021

Here is tests of the 1.4.0 + all master patches + below patch

--- a/traceback2/tests/test_traceback.py~       2015-03-09 06:56:36.000000000 +0000
+++ b/traceback2/tests/test_traceback.py        2021-12-26 07:05:23.292113915 +0000
@@ -25,7 +25,7 @@
     else:
         def raise_from(value, from_value):
             raise value
-import unittest2 as unittest
+import unittest
 import testtools
 from testtools.matchers import DocTestMatches, Equals, MatchesAny

which switches fto standard unitest.

Here it is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-traceback2-1.4.0-3.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-traceback2-1.4.0-3.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
Using --randomly-seed=1551105734
rootdir: /home/tkloczko/rpmbuild/BUILD/traceback2-1.4.0
plugins: freezegun-0.4.2, mock-3.6.1, randomly-3.10.3, timeout-2.0.2, flaky-3.7.0, cov-3.0.0
collected 49 items

traceback2/tests/test_traceback.py ...........F.............s......s.........F......                                                                                 [100%]

================================================================================= FAILURES =================================================================================
_______________________________________________________________ PyExcReportingTests.test_context_suppression _______________________________________________________________
'NoneType' object is not iterable

During handling of the above exception, another exception occurred:
NOTE: Incompatible Exception Representation, displaying natively:

testtools.testresult.real._StringException: Traceback (most recent call last):
  File "/home/tkloczko/rpmbuild/BUILD/traceback2-1.4.0/traceback2/tests/test_traceback.py", line 419, in test_context_suppression
    self.assertThat(lines, DocTestMatches("""\
  File "/usr/lib/python3.8/site-packages/testtools/testcase.py", line 480, in assertThat
    raise mismatch_error
testtools.matchers._impl.MismatchError: Expected:
    Traceback (most recent call last):
      File "...traceback2/tests/test_traceback.py", line ..., in test_context_suppression
        raise_from(ZeroDivisionError, None)
      File "<string>", line 2, in raise_from
    ZeroDivisionError
Got:
    Traceback (most recent call last):
      File "/home/tkloczko/rpmbuild/BUILD/traceback2-1.4.0/traceback2/tests/test_traceback.py", line 414, in test_context_suppression
        raise_from(ZeroDivisionError, None)
      File "<string>", line 3, in raise_from
    ZeroDivisionError
_______________________________________________________________________ TestStack.test_format_locals _______________________________________________________________________

self = <traceback2.tests.test_traceback.TestStack testMethod=test_format_locals>

    def test_format_locals(self):
        def some_inner(k, v):
            a = 1
            b = 2
            return traceback.StackSummary.extract(
                traceback.walk_stack(None), capture_locals=True, limit=1)
        s = some_inner(3, 4)
>       self.assertEqual(
            ['  File "' + FNAME + '", line 651, '
             'in some_inner\n'
             '    traceback.walk_stack(None), capture_locals=True, limit=1)\n'
             '    a = 1\n'
             '    b = 2\n'
             '    k = 3\n'
             '    v = 4\n'
            ], s.format())
E       AssertionError: Lists differ: ['  F[91 chars]ne 651, in some_inner\n    traceback.walk_stac[81 chars]4\n'] != ['  F[91 chars]ne 650, in some_inner\n    return traceback.St[62 chars]4\n']
E
E       First differing element 0:
E       '  Fi[90 chars]ne 651, in some_inner\n    traceback.walk_stac[80 chars] 4\n'
E       '  Fi[90 chars]ne 650, in some_inner\n    return traceback.St[61 chars] 4\n'
E
E         ['  File '
E          '"/home/tkloczko/rpmbuild/BUILD/traceback2-1.4.0/traceback2/tests/test_traceback.py", '
E       -  'line 651, in some_inner\n'
E       ?          ^
E
E       +  'line 650, in some_inner\n'
E       ?          ^
E
E       -  '    traceback.walk_stack(None), capture_locals=True, limit=1)\n'
E       +  '    return traceback.StackSummary.extract(\n'
E          '    a = 1\n'
E          '    b = 2\n'
E          '    k = 3\n'
E          '    v = 4\n']

traceback2/tests/test_traceback.py:653: AssertionError
============================================================================= warnings summary =============================================================================
../../../../../usr/lib/python3.8/site-packages/pytest_freezegun.py:17: 98 warnings
  /usr/lib/python3.8/site-packages/pytest_freezegun.py:17: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    if LooseVersion(pytest.__version__) < LooseVersion('3.6.0'):

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================================================================= short test summary info ==========================================================================
SKIPPED [1] traceback2/tests/test_traceback.py:899: Applies to 2.x only.
SKIPPED [1] traceback2/tests/test_traceback.py:867: Applies to 2.x only.
FAILED traceback2/tests/test_traceback.py::PyExcReportingTests::test_context_suppression
FAILED traceback2/tests/test_traceback.py::TestStack::test_format_locals - AssertionError: Lists differ: ['  F[91 chars]ne 651, in some_inner\n    traceback.walk_stac[81...
=========================================================== 2 failed, 45 passed, 2 skipped, 98 warnings in 0.99s ===========================================================

@kloczek
Copy link
Contributor Author

kloczek commented Aug 30, 2023

Gentle ping .. any update? 🤔

@jelmer
Copy link
Member

jelmer commented Aug 30, 2023

Same as for the other projects; we don't use pytest, so if you'd like to see this project support pytest, you're going to have to create a PR to make it work with that.

@jelmer jelmer changed the title 1.4.0: pytest is failing support pytest Aug 30, 2023
@kloczek
Copy link
Contributor Author

kloczek commented Aug 30, 2023

So would you accept unittest2->unittest migration?

Other reported issue are pointing on tested code issue so it is hard to solve that without proper traceback2 code knowledge.

@jelmer
Copy link
Member

jelmer commented Aug 30, 2023

Yeah, I think we can migrate to unittest at this point since we've dropped python<2.7 support

@kloczek
Copy link
Contributor Author

kloczek commented Aug 30, 2023

OK will make PR.
BTW migration from unittest to pytest is not necessary because correctly written unittest based test suite can be correctly handled by pytest. On use pytest instead pytest however some issues maybe exposed because pytest is far more advances and sensitive on some issue.
However if you would decide to move completely to pytest this can be easy done using unittest2pytest module https://github.com/pytest-dev/unittest2pytest/

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

No branches or pull requests

2 participants