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

ValueError raised when running SWSS tests on some Debian releases #3382

Open
mramezani95 opened this issue Nov 20, 2024 · 1 comment
Open

Comments

@mramezani95
Copy link
Contributor

Some of the tests in test_mirror.py and test_vlan.py are skipped for Debian 8.9 or before by using the following line:

@pytest.mark.skipif(StrictVersion(distro.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support")

Some Debian release versions are simple integers (e.g., 10, 11, 12, etc.). Running these tests on such Debian releases causes the constructor of StrictVersion to raise a ValueError, because it does not accept simple integers.
For example, I tried to run the tests on Debian 11 (bullseye) using the command sudo python3 -m py.test and received the following errors:

======================================================== ERRORS ========================================================
___________________________________________ ERROR collecting test_mirror.py ____________________________________________
test_mirror.py:10: in <module>
    class TestMirror(object):
test_mirror.py:382: in TestMirror
    ???
/usr/lib/python3.9/distutils/version.py:40: in __init__
    self.parse(vstring)
/usr/lib/python3.9/distutils/version.py:137: in parse
    raise ValueError("invalid version number '%s'" % vstring)
E   ValueError: invalid version number '11'
____________________________________________ ERROR collecting test_vlan.py _____________________________________________
test_vlan.py:10: in <module>
    class TestVlan(object):
test_vlan.py:161: in TestVlan
    ???
/usr/lib/python3.9/distutils/version.py:40: in __init__
    self.parse(vstring)
/usr/lib/python3.9/distutils/version.py:137: in parse
    raise ValueError("invalid version number '%s'" % vstring)
E   ValueError: invalid version number '11'
@wdoekes
Copy link

wdoekes commented Nov 21, 2024

For debian version compares, it makes sense to use apt_pkg:

>>> import apt_pkg
>>> apt_pkg.init()
>>> apt_pkg.version_compare('10', '8.9')
1

^- sorts above

But otherwise LooseVersion would be fine here too:

>>> from distutils.version import LooseVersion
>>> LooseVersion('10') < LooseVersion('8.9')
False

Or packaging version:

>>> from packaging.version import Version, InvalidVersion
>>> Version('10') < Version('8.9')
False

Also note that distro.linux_distribution() is deprecated:

>>> import distro
>>> distro.linux_distribution()[1]
<stdin>:1: DeprecationWarning: distro.linux_distribution() is deprecated. It should only be used as a compatibility shim with Python's platform.linux_distribution(). Please use distro.id(), distro.version() and distro.name() instead.
'22.04'
>>> distro.version()
'22.04'

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