Skip to content

Commit fc7f3bd

Browse files
committed
feat: support customisation for supported_targets and preview_targets by contextvar
1 parent 52e69f4 commit fc7f3bd

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

docs/usages/markers.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ Target Extension
8181

8282
In scenarios where the supported targets are [esp32, esp32c3, esp32s3], ``idf_parametrize`` simplifies the process of creating parameterized tests by automatically expanding the target list.
8383

84+
By default, the values for ``SUPPORTED_TARGETS`` and ``PREVIEW_TARGETS`` are imported from:
85+
86+
.. code:: python
87+
88+
from esp_bool_parser import PREVIEW_TARGETS, SUPPORTED_TARGETS
89+
90+
However, you can propagate custom values by using the following:
91+
92+
.. code:: python
93+
94+
from pytest_embedded_idf.utils import supported_targets, preview_targets
95+
96+
supported_targets.set(CUSTOM_SUPPORT_TARGETS)
97+
preview_targets.set(CUSTOM_SUPPORT_TARGETS)
98+
8499
**Example:**
85100

86101
.. code:: python

pytest-embedded-idf/pytest_embedded_idf/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import typing as t
2+
from contextvars import ContextVar
23

34
import pytest
45
from esp_bool_parser import PREVIEW_TARGETS, SUPPORTED_TARGETS
56

7+
supported_targets = ContextVar('supported_targets', default=SUPPORTED_TARGETS)
8+
preview_targets = ContextVar('preview_targets', default=PREVIEW_TARGETS)
9+
610

711
def _expand_target_values(values: t.List[t.List[t.Any]], target_index: int) -> t.List[t.List[t.Any]]:
812
"""
@@ -13,11 +17,11 @@ def _expand_target_values(values: t.List[t.List[t.Any]], target_index: int) -> t
1317
target = value[target_index]
1418
if target == 'supported_targets':
1519
expanded_values.extend([
16-
value[:target_index] + [target] + value[target_index + 1 :] for target in SUPPORTED_TARGETS
20+
value[:target_index] + [target] + value[target_index + 1 :] for target in supported_targets.get()
1721
])
1822
elif target == 'preview_targets':
1923
expanded_values.extend([
20-
value[:target_index] + [target] + value[target_index + 1 :] for target in PREVIEW_TARGETS
24+
value[:target_index] + [target] + value[target_index + 1 :] for target in preview_targets.get()
2125
])
2226
else:
2327
expanded_values.append(value)

0 commit comments

Comments
 (0)