avocado-framework / avocado

Avocado is a set of tools and libraries to help with automated testing. One can call it a test framework with benefits. Native tests are written in Python and they follow the unittest pattern, but any executable can serve as a test.
https://avocado-framework.github.io/
Other
345 stars 343 forks source link

avocado.utils.kernel.check_version is broken with imports and actual check #6058

Open clebergnu opened 3 weeks ago

clebergnu commented 3 weeks ago

Describe the bug Commit 58738b61a8bd6af542ff82a2ccccb49551c48c1b fixed an import time compatibility issue on avocado.utils.kernel with regards to either pkg_resources or packaging.

That in fact only masked some other problems:

  1. The version module is not directly accessible in packaging
  2. The behavior of version.parse() is different between the one coming from pkg_resources and from packaging.

Steps to reproduce To reproduce 1, run:

python3 -c 'import packaging; packaging.version.parse("1.2.3")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'packaging' has no attribute 'version'

To reproduce 2, on a system with packaging, run:

$ python3 -c 'from packaging.version import parse; parse("6.11.4-201.fc40.x86_64")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.12/site-packages/packaging/version.py", line 54, in parse
    return Version(version)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/packaging/version.py", line 200, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: '6.11.4-201.fc40.x86_64'

While on a system with pkg_resources you'd get:

python3 -c 'import pkg_resources; print(pkg_resources.packaging.version.parse("6.11.4-201.fc40.x86_64"))'
6.11.4-201.fc40.x86_64