hdmf icon indicating copy to clipboard operation
hdmf copied to clipboard

[Bug]: Test collection fails for three tests with pytest 8.2.0

Open penguinpee opened this issue 1 year ago • 6 comments

What happened?

Fedora is preparing to upgrade pytest to 8.x (currently 8.2.0). When running tests with that version of pytest, three test cannot be collected and fail with TypeError.

I used the approach below (using an empty directory) since I encountered issues with test collection previously. In this case, however, it didn't make a difference. Step 1 to 3 can be omitted, yielding the same result.

Steps to Reproduce

mkdir empty
cd empty
ln -s ../tests ../pyproject.toml .
pytest -vv

Traceback

============================================================================================================================= test session starts ==============================================================================================================================
platform linux -- Python 3.12.3, pytest-8.2.0, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /builddir/build/BUILD/hdmf-3.13.0/empty
configfile: pyproject.toml
collected 1504 items / 3 errors                                                                                                                                                                                                                                                

==================================================================================================================================== ERRORS ====================================================================================================================================
______________________________________________________________________________________________________ ERROR collecting tests/unit/build_tests/mapper_tests/test_build.py ______________________________________________________________________________________________________
/usr/lib/python3.12/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
/usr/lib/python3.12/site-packages/_pytest/runner.py:389: in collect
    return list(collector.collect())
/usr/lib/python3.12/site-packages/_pytest/unittest.py:90: in collect
    self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid)
/usr/lib/python3.12/site-packages/_pytest/unittest.py:75: in newinstance
    return self.obj("runTest")
E   TypeError: Can't instantiate abstract class BuildGroupExtAttrsMixin without an implementation for abstract method 'setUpBarHolderSpec'
______________________________________________________________________________________________________ ERROR collecting tests/unit/build_tests/mapper_tests/test_build.py ______________________________________________________________________________________________________
/usr/lib/python3.12/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
/usr/lib/python3.12/site-packages/_pytest/runner.py:389: in collect
    return list(collector.collect())
/usr/lib/python3.12/site-packages/_pytest/unittest.py:90: in collect
    self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid)
/usr/lib/python3.12/site-packages/_pytest/unittest.py:75: in newinstance
    return self.obj("runTest")
E   TypeError: Can't instantiate abstract class BuildDatasetExtAttrsMixin without an implementation for abstract method 'get_refined_bar_data_spec'
_________________________________________________________________________________________________________ ERROR collecting tests/unit/validator_tests/test_validate.py _________________________________________________________________________________________________________
/usr/lib/python3.12/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
/usr/lib/python3.12/site-packages/_pytest/runner.py:389: in collect
    return list(collector.collect())
/usr/lib/python3.12/site-packages/_pytest/unittest.py:90: in collect
    self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid)
/usr/lib/python3.12/site-packages/_pytest/unittest.py:75: in newinstance
    return self.obj("runTest")
E   TypeError: Can't instantiate abstract class ValidatorTestBase without an implementation for abstract method 'getSpecs'
=========================================================================================================================== short test summary info ============================================================================================================================
ERROR tests/unit/build_tests/mapper_tests/test_build.py::BuildGroupExtAttrsMixin - TypeError: Can't instantiate abstract class BuildGroupExtAttrsMixin without an implementation for abstract method 'setUpBarHolderSpec'
ERROR tests/unit/build_tests/mapper_tests/test_build.py::BuildDatasetExtAttrsMixin - TypeError: Can't instantiate abstract class BuildDatasetExtAttrsMixin without an implementation for abstract method 'get_refined_bar_data_spec'
ERROR tests/unit/validator_tests/test_validate.py::ValidatorTestBase - TypeError: Can't instantiate abstract class ValidatorTestBase without an implementation for abstract method 'getSpecs'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================================================== 3 errors in 1.15s ===============================================================================================================================

Operating System

Linux

Python Executable

Python

Python Version

3.12

Package Versions

Python 3.12.3 pytest 8.2.0 hdmf 3.13.0 h5py 3.11.0 jsonschema 4.19.1 numpy 1.26.4 pandas 2.2.1 ruamel-yaml 0.18.5 scipy 1.11.3

We are using the packages available from the Fedora repositories. Listed are the dependencies for HDMF.

penguinpee avatar May 14 '24 14:05 penguinpee

Hi @penguinpee I will discuss with the team. That being said the error does not appear on our scheduled test workflows as we are using pytest 7.4.3.

mavaylon1 avatar May 15 '24 13:05 mavaylon1

Hi @penguinpee after discussion with the team, we will update to pytest 8 in the future. I will post a deadline here when we have one.

mavaylon1 avatar May 20 '24 20:05 mavaylon1

Thanks! Should I have any news with regards to that issue, I'll post an update here.

penguinpee avatar May 20 '24 20:05 penguinpee

This appears to be an issue in pytest trying to instantiat abstract classes: pytest-dev/pytest#12275

It will be fixed in release 8.3.0.

penguinpee avatar May 29 '24 16:05 penguinpee

Wonderful. Let's see!

mavaylon1 avatar May 29 '24 16:05 mavaylon1

The workaround using conftest.py, mentioned in the ticket, works.

penguinpee avatar May 29 '24 17:05 penguinpee

Now that Fedora has pytest 8.3.3, I tried removing the patch corresponding to the workaround described in https://github.com/pytest-dev/pytest/issues/12275#issuecomment-2096751244 from Fedora’s python-hdmf package and didn’t observe any problems. I would say that this confirms the fix is in pytest 8.3, and this issue could be closed.

musicinmybrain avatar Nov 27 '24 19:11 musicinmybrain

Thanks for checking back in @musicinmybrain !

rly avatar Dec 19 '24 23:12 rly