mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-26 12:50:30 +00:00
ci: apply idf-ci pytest plugin
Removed - target markers. Now must use target as parametrization in esp-idf - host test markers. Now will be automatically added with linux target and qemu marker
This commit is contained in:
90
conftest.py
90
conftest.py
@@ -17,7 +17,6 @@ if os.path.join(os.path.dirname(__file__), 'tools', 'ci') not in sys.path:
|
||||
if os.path.join(os.path.dirname(__file__), 'tools', 'ci', 'python_packages') not in sys.path:
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), 'tools', 'ci', 'python_packages'))
|
||||
|
||||
import glob
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
@@ -36,20 +35,17 @@ from _pytest.config import Config
|
||||
from _pytest.fixtures import FixtureRequest
|
||||
from artifacts_handler import ArtifactType
|
||||
from dynamic_pipelines.constants import TEST_RELATED_APPS_DOWNLOAD_URLS_FILENAME
|
||||
from idf_ci_local.app import import_apps_from_txt
|
||||
from idf_ci import PytestCase
|
||||
from idf_ci.idf_pytest import IDF_CI_PYTEST_CASE_KEY
|
||||
from idf_ci_local.uploader import AppDownloader
|
||||
from idf_ci_local.uploader import AppUploader
|
||||
from idf_ci_utils import IDF_PATH
|
||||
from idf_ci_utils import idf_relpath
|
||||
from idf_pytest.constants import DEFAULT_LOGDIR
|
||||
from idf_pytest.constants import DEFAULT_SDKCONFIG
|
||||
from idf_pytest.constants import ENV_MARKERS
|
||||
from idf_pytest.constants import SPECIAL_MARKERS
|
||||
from idf_pytest.constants import TARGET_MARKERS
|
||||
from idf_pytest.constants import PytestCase
|
||||
from idf_pytest.plugin import IDF_PYTEST_EMBEDDED_KEY
|
||||
from idf_pytest.plugin import ITEM_PYTEST_CASE_KEY
|
||||
from idf_pytest.plugin import IdfPytestEmbedded
|
||||
from idf_pytest.plugin import IDF_LOCAL_PLUGIN_KEY
|
||||
from idf_pytest.plugin import IdfLocalPlugin
|
||||
from idf_pytest.plugin import requires_elf_or_map
|
||||
from idf_pytest.utils import format_case_id
|
||||
from pytest_embedded.plugin import multi_dut_argument
|
||||
from pytest_embedded.plugin import multi_dut_fixture
|
||||
@@ -85,7 +81,7 @@ def config(request: FixtureRequest) -> str:
|
||||
@pytest.fixture
|
||||
@multi_dut_fixture
|
||||
def target(request: FixtureRequest, dut_total: int, dut_index: int) -> str:
|
||||
plugin = request.config.stash[IDF_PYTEST_EMBEDDED_KEY]
|
||||
plugin = request.config.stash[IDF_LOCAL_PLUGIN_KEY]
|
||||
|
||||
if dut_total == 1:
|
||||
return plugin.target[0] # type: ignore
|
||||
@@ -205,11 +201,11 @@ def build_dir(
|
||||
valid build directory
|
||||
"""
|
||||
# download from minio on CI
|
||||
case: PytestCase = request._pyfuncitem.stash[ITEM_PYTEST_CASE_KEY]
|
||||
case: PytestCase = request.node.stash[IDF_CI_PYTEST_CASE_KEY]
|
||||
if app_downloader:
|
||||
# somehow hardcoded...
|
||||
app_build_path = os.path.join(idf_relpath(app_path), f'build_{target}_{config}')
|
||||
if case.requires_elf_or_map:
|
||||
if requires_elf_or_map(case):
|
||||
app_downloader.download_app(app_build_path)
|
||||
else:
|
||||
app_downloader.download_app(app_build_path, ArtifactType.BUILD_DIR_WITHOUT_MAP_AND_ELF_FILES)
|
||||
@@ -403,10 +399,6 @@ def dev_user(request: FixtureRequest) -> str:
|
||||
##################
|
||||
def pytest_addoption(parser: pytest.Parser) -> None:
|
||||
idf_group = parser.getgroup('idf')
|
||||
idf_group.addoption(
|
||||
'--sdkconfig',
|
||||
help='sdkconfig postfix, like sdkconfig.ci.<config>. (Default: None, which would build all found apps)',
|
||||
)
|
||||
idf_group.addoption(
|
||||
'--dev-user',
|
||||
help='user name associated with some specific device/service used during the test execution',
|
||||
@@ -415,12 +407,6 @@ def pytest_addoption(parser: pytest.Parser) -> None:
|
||||
'--dev-passwd',
|
||||
help='password associated with some specific device/service used during the test execution',
|
||||
)
|
||||
idf_group.addoption(
|
||||
'--app-info-filepattern',
|
||||
help='glob pattern to specify the files that include built app info generated by '
|
||||
'`idf-build-apps --collect-app-info ...`. will not raise ValueError when binary '
|
||||
'paths not exist in local file system if not listed recorded in the app info.',
|
||||
)
|
||||
idf_group.addoption(
|
||||
'--pipeline-id',
|
||||
help='main pipeline id, not the child pipeline id. Specify this option to download the artifacts '
|
||||
@@ -437,63 +423,15 @@ def pytest_configure(config: Config) -> None:
|
||||
supported_targets.set(SUPPORTED_TARGETS)
|
||||
preview_targets.set(PREVIEW_TARGETS)
|
||||
|
||||
# cli option "--target"
|
||||
target = [_t.strip().lower() for _t in (config.getoption('target', '') or '').split(',') if _t.strip()]
|
||||
|
||||
# add markers based on idf_pytest/constants.py
|
||||
for name, description in {
|
||||
**TARGET_MARKERS,
|
||||
**ENV_MARKERS,
|
||||
**SPECIAL_MARKERS,
|
||||
}.items():
|
||||
config.addinivalue_line('markers', f'{name}: {description}')
|
||||
|
||||
help_commands = ['--help', '--fixtures', '--markers', '--version']
|
||||
for cmd in help_commands:
|
||||
if cmd in config.invocation_params.args:
|
||||
target = ['unneeded']
|
||||
break
|
||||
|
||||
markexpr = config.getoption('markexpr') or ''
|
||||
# check marker expr set via "pytest -m"
|
||||
if not target and markexpr:
|
||||
# we use `-m "esp32 and generic"` in our CI to filter the test cases
|
||||
# this doesn't cover all use cases, but fit what we do in CI.
|
||||
for marker in markexpr.split('and'):
|
||||
marker = marker.strip()
|
||||
if marker in TARGET_MARKERS:
|
||||
target.append(marker)
|
||||
|
||||
# "--target" must be set
|
||||
if not target:
|
||||
raise SystemExit(
|
||||
"""Pass `--target TARGET[,TARGET...]` to specify all targets the test cases are using.
|
||||
- for single DUT, we run with `pytest --target esp32`
|
||||
- for multi DUT, we run with `pytest --target esp32,esp32,esp32s2` to indicate all DUTs
|
||||
"""
|
||||
)
|
||||
|
||||
apps = None
|
||||
app_info_filepattern = config.getoption('app_info_filepattern')
|
||||
if app_info_filepattern:
|
||||
apps = []
|
||||
for f in glob.glob(os.path.join(IDF_PATH, app_info_filepattern)):
|
||||
apps.extend(import_apps_from_txt(f))
|
||||
|
||||
if '--collect-only' not in config.invocation_params.args:
|
||||
config.stash[IDF_PYTEST_EMBEDDED_KEY] = IdfPytestEmbedded(
|
||||
config_name=config.getoption('sdkconfig'),
|
||||
target=target,
|
||||
apps=apps,
|
||||
)
|
||||
config.pluginmanager.register(config.stash[IDF_PYTEST_EMBEDDED_KEY])
|
||||
config.stash[IDF_LOCAL_PLUGIN_KEY] = IdfLocalPlugin()
|
||||
config.pluginmanager.register(config.stash[IDF_LOCAL_PLUGIN_KEY])
|
||||
|
||||
|
||||
def pytest_unconfigure(config: Config) -> None:
|
||||
_pytest_embedded = config.stash.get(IDF_PYTEST_EMBEDDED_KEY, None)
|
||||
if _pytest_embedded:
|
||||
del config.stash[IDF_PYTEST_EMBEDDED_KEY]
|
||||
config.pluginmanager.unregister(_pytest_embedded)
|
||||
idf_local_plugin = config.stash.get(IDF_LOCAL_PLUGIN_KEY, None)
|
||||
if idf_local_plugin:
|
||||
del config.stash[IDF_LOCAL_PLUGIN_KEY]
|
||||
config.pluginmanager.unregister(idf_local_plugin)
|
||||
|
||||
|
||||
dut_artifacts_url = []
|
||||
|
||||
Reference in New Issue
Block a user