Skip to content

Commit 857adb2

Browse files
fundakolnashif
authored andcommitted
twister: Fix failing tests on CI with Python 3.12
This change is removing some deprecation warnings which for some reason causing failing tests with Python 3.12 on CI #76877. Also, it fixes warnings from pytest like: PytestCollectionWarning: cannot collect test class 'TestPlan' because it has a __init__ constructor (from: scripts/tests/twister/test_testplan.py) Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
1 parent 6a101ae commit 857adb2

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

scripts/pylib/twister/twisterlib/environment.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
# Copyright 2022 NXP
66
# SPDX-License-Identifier: Apache-2.0
77

8-
import os
9-
import pkg_resources
10-
import sys
11-
from pathlib import Path
8+
import argparse
129
import json
1310
import logging
14-
import subprocess
15-
import shutil
11+
import os
1612
import re
17-
import argparse
13+
import shutil
14+
import subprocess
15+
import sys
1816
from datetime import datetime, timezone
17+
from importlib import metadata
18+
from pathlib import Path
19+
from typing import Generator
20+
1921
from twisterlib.coverage import supported_coverage_formats
2022

2123
logger = logging.getLogger('twister')
@@ -40,13 +42,22 @@
4042
# Note "normalization" is different from canonicalization, see os.path.
4143
canonical_zephyr_base = os.path.realpath(ZEPHYR_BASE)
4244

43-
installed_packages = [pkg.project_name for pkg in pkg_resources.working_set] # pylint: disable=not-an-iterable
45+
46+
def _get_installed_packages() -> Generator[str, None, None]:
47+
"""Return list of installed python packages."""
48+
for dist in metadata.distributions():
49+
yield dist.metadata['Name']
50+
51+
52+
installed_packages: list[str] = list(_get_installed_packages())
4453
PYTEST_PLUGIN_INSTALLED = 'pytest-twister-harness' in installed_packages
4554

55+
4656
def norm_path(astring):
4757
newstring = os.path.normpath(astring).replace(os.sep, '/')
4858
return newstring
4959

60+
5061
def add_parse_arguments(parser = None):
5162
if parser is None:
5263
parser = argparse.ArgumentParser(

scripts/pylib/twister/twisterlib/harness.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ def _check_result(self, line):
668668

669669

670670
class Test(Harness):
671+
__test__ = False # for pytest to skip this class when collects tests
671672
RUN_PASSED = "PROJECT EXECUTION SUCCESSFUL"
672673
RUN_FAILED = "PROJECT EXECUTION FAILED"
673674
test_suite_start_pattern = r"Running TESTSUITE (?P<suite_name>.*)"

scripts/pylib/twister/twisterlib/testplan.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class TestLevel:
7777
levels = []
7878
scenarios = []
7979

80+
8081
class TestPlan:
82+
__test__ = False # for pytest to skip this class when collects tests
8183
config_re = re.compile('(CONFIG_[A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$')
8284
dt_re = re.compile('([A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$')
8385

0 commit comments

Comments
 (0)