bitarray icon indicating copy to clipboard operation
bitarray copied to clipboard

2.9.2: pytest fails

Open kloczek opened this issue 1 year ago • 4 comments

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 avatar Mar 08 '24 15:03 kloczek

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

kloczek avatar Mar 08 '24 15:03 kloczek

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.

ilanschnell avatar Mar 08 '24 20:03 ilanschnell

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 avatar Mar 08 '24 22:03 kloczek

Using setup.py is deprecated more than two years 😄

kloczek avatar Mar 08 '24 22:03 kloczek

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.

kloczek avatar May 24 '24 09:05 kloczek

From the root of the source, you can also run just run pytest. See https://github.com/ilanschnell/bitarray/blob/master/pytest.ini

ilanschnell avatar Jun 28 '24 04:06 ilanschnell