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

2.9.2: pytest fails #215

Open
kloczek opened this issue Mar 8, 2024 · 5 comments
Open

2.9.2: pytest fails #215

kloczek opened this issue Mar 8, 2024 · 5 comments

Comments

@kloczek
Copy link

kloczek commented Mar 8, 2024

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

  • python3 -sBm build -w --no-isolation
  • because I'm calling build with --no-isolation I'm using during all processes only locally installed modules
  • install .whl file in </install/prefix> using installer module
  • run pytest with $PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>
  • build is performed in env which is cut off from access to the public network (pytest is executed with -m "not network")
Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-bitarray-2.9.2-2.fc36.x86_64/usr/lib64/python3.9/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-bitarray-2.9.2-2.fc36.x86_64/usr/lib/python3.9/site-packages
+ /usr/bin/pytest -ra -m 'not network' --import-mode=importlib
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.9.18, pytest-8.1.0, pluggy-1.4.0
rootdir: /home/tkloczko/rpmbuild/BUILD/bitarray-2.9.2
configfile: pytest.ini
testpaths: bitarray
collected 502 items

bitarray/test_bitarray.py ...........................................................................................................F............................................... [ 30%]
...............................................................................................................................................................................F..... [ 66%]
.......F..                                                                                                                                                                            [ 68%]
bitarray/test_util.py ............................................................................................................................................................    [100%]

========================================================================================= FAILURES ==========================================================================================
________________________________________________________________________________ PickleTests.test_attributes ________________________________________________________________________________

self = <bitarray.test_bitarray.PickleTests testMethod=test_attributes>

    def test_attributes(self):
        a = frozenbitarray("00110")
        # as a is a subclass of bitarray, we can have attributes
        a.x = "bar"
        a.y = "baz"

>       b = pickle.loads(pickle.dumps(a))
E       _pickle.PicklingError: Can't pickle <class 'bitarray.frozenbitarray'>: it's not the same object as bitarray.frozenbitarray

bitarray/test_bitarray.py:1810: PicklingError
_______________________________________________________________________________ TestsFrozenbitarray.test_copy _______________________________________________________________________________

self = <bitarray.test_bitarray.TestsFrozenbitarray testMethod=test_copy>

    def test_copy(self):
        a = frozenbitarray('101')
        # not only .copy() creates new frozenbitarray which are read-only
        for b in [a, a.copy(), 3 * a, 5 * a, a & bitarray('110'),
                  a >> 2, ~a, a + bitarray(8*'1'),
                  a[:], a[::2], a[[0, 1]], a[bitarray('011')]]:
            self.assertIsType(b, 'frozenbitarray')
>           self.assertTrue(b.readonly)
E           AssertionError: False is not true

bitarray/test_bitarray.py:5032: AssertionError
______________________________________________________________________________ TestsFrozenbitarray.test_pickle ______________________________________________________________________________

self = <bitarray.test_bitarray.TestsFrozenbitarray testMethod=test_pickle>

    def test_pickle(self):
        for a in self.randombitarrays():
            f = frozenbitarray(a)
            f.foo = 42  # unlike bitarray itself, we can have attributes
>           g = pickle.loads(pickle.dumps(f))
E           _pickle.PicklingError: Can't pickle <class 'bitarray.frozenbitarray'>: it's not the same object as bitarray.frozenbitarray

bitarray/test_bitarray.py:5119: PicklingError
===================================================================================== warnings summary ======================================================================================
bitarray/test_util.py: 34 warnings
  /home/tkloczko/rpmbuild/BUILDROOT/python-bitarray-2.9.2-2.fc36.x86_64/usr/lib64/python3.9/site-packages/bitarray/util.py:143: DeprecationWarning: make_endian() is deprecated and will be removed in bitarray 3.0 - use bitarray(..., endian=...) instead
    warn("make_endian() is deprecated and will be removed in bitarray 3.0 - "

bitarray/test_util.py: 491 warnings
  /home/tkloczko/rpmbuild/BUILDROOT/python-bitarray-2.9.2-2.fc36.x86_64/usr/lib64/python3.9/site-packages/bitarray/util.py:66: DeprecationWarning: rindex() is deprecated and will be removed in bitarray 3.0 - use .index(..., right=True) method instead.
    warn("rindex() is deprecated and will be removed in bitarray 3.0 - "

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ==================================================================================
FAILED bitarray/test_bitarray.py::PickleTests::test_attributes - _pickle.PicklingError: Can't pickle <class 'bitarray.frozenbitarray'>: it's not the same object as bitarray.frozenbitarray
FAILED bitarray/test_bitarray.py::TestsFrozenbitarray::test_copy - AssertionError: False is not true
FAILED bitarray/test_bitarray.py::TestsFrozenbitarray::test_pickle - _pickle.PicklingError: Can't pickle <class 'bitarray.frozenbitarray'>: it's not the same object as bitarray.frozenbitarray
======================================================================== 3 failed, 499 passed, 525 warnings in 1.61s ========================================================================

Please let me know if you need more details or want me to perform some diagnostics.

@kloczek
Copy link
Author

kloczek commented Mar 8, 2024

BTW is it not would be better to move bitarray/test_*.py files to tests/ to not install those files? 🤔

@ilanschnell
Copy link
Owner

Thank you for using bitarray and reporting this issue. What is the reasoning for using the command python3 -sBm build -w --no-isolation? I've never seen this before. If you want to build wheels, you can use python setup.py bdist_wheel, or install bitarray using python setup.py install.

@kloczek
Copy link
Author

kloczek commented Mar 8, 2024

Thank you for using bitarray and reporting this issue. What is the reasoning for using the command python3 -sBm build -w --no-isolation? I've never seen this before. If you want to build wheels, you can use python setup.py bdist_wheel, or install bitarray using python setup.py install.

Reason is described in PEP517 https://peps.python.org/pep-0517/ 😋

@kloczek
Copy link
Author

kloczek commented Mar 8, 2024

Using setup.py is deprecated more than two years 😄

@kloczek
Copy link
Author

kloczek commented May 24, 2024

Looks like I found solution. To pytest args needs to be added --pyargs bitarray

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-bitarray-2.9.2-2.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-bitarray-2.9.2-2.fc37.x86_64/usr/lib/python3.10/site-packages
+ /usr/bin/pytest -ra -m 'not network' --pyargs bitarray
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.10.14, pytest-8.2.1, pluggy-1.5.0
rootdir: /home/tkloczko/rpmbuild/BUILD/bitarray-2.9.2
configfile: pytest.ini
collected 502 items

test_bitarray.py .................................................................................................................................................................... [ 32%]
..................................................................................................................................................................................... [ 68%]
.                                                                                                                                                                                     [ 68%]
test_util.py ............................................................................................................................................................             [100%]

===================================================================================== warnings summary ======================================================================================
test_util.py: 34 warnings
  /home/tkloczko/rpmbuild/BUILDROOT/python-bitarray-2.9.2-2.fc37.x86_64/usr/lib64/python3.10/site-packages/bitarray/util.py:142: DeprecationWarning: make_endian() is deprecated and will be removed in bitarray 3.0 - use bitarray(..., endian=...) instead
    warn("make_endian() is deprecated and will be removed in bitarray 3.0 - "

test_util.py: 491 warnings
  /home/tkloczko/rpmbuild/BUILDROOT/python-bitarray-2.9.2-2.fc37.x86_64/usr/lib64/python3.10/site-packages/bitarray/util.py:65: DeprecationWarning: rindex() is deprecated and will be removed in bitarray 3.0 - use .index(..., right=True) method instead.
    warn("rindex() is deprecated and will be removed in bitarray 3.0 - "

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================= 502 passed, 525 warnings in 3.11s =============================================================================

It would be good to add --pyargs bitarray and clean above warnings.

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

No branches or pull requests

2 participants