pytest-embedded 2.10.0__tar.gz → 2.10.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-embedded
3
- Version: 2.10.0
3
+ Version: 2.10.1
4
4
  Summary: A pytest plugin that designed for embedded testing.
5
5
  Author-email: Fu Hanxi <fuhanxi@espressif.com>
6
6
  Requires-Python: >=3.10
@@ -6,4 +6,4 @@ from .dut_factory import DutFactory
6
6
 
7
7
  __all__ = ['App', 'Dut', 'DutFactory']
8
8
 
9
- __version__ = '2.10.0'
9
+ __version__ = '2.10.1'
@@ -16,6 +16,7 @@ import warnings
16
16
  import xml.dom.minidom
17
17
  from collections import Counter
18
18
  from operator import itemgetter
19
+ from pathlib import Path
19
20
 
20
21
  import filelock
21
22
  import pytest
@@ -73,6 +74,12 @@ _T = t.TypeVar('_T')
73
74
 
74
75
 
75
76
  def pytest_addoption(parser: pytest.Parser):
77
+ parser.addini(
78
+ 'junit_app_path_relative_to_root',
79
+ 'Record JUnit app_path relative to the pytest root directory when the app is inside it.',
80
+ type='bool',
81
+ default=False,
82
+ )
76
83
  base_group = parser.getgroup('embedded')
77
84
  base_group.addoption(
78
85
  '--count',
@@ -873,7 +880,13 @@ def embedded_services(request: FixtureRequest) -> str | None:
873
880
  def app_path(request: FixtureRequest, test_file_path: str, record_xml_attribute) -> str | None:
874
881
  """Enable parametrization for the same cli option"""
875
882
  res = _request_param_or_config_option_or_default(request, 'app_path', os.path.dirname(test_file_path))
876
- record_xml_attribute('app_path', res)
883
+ report_path = res
884
+ if res and request.config.getini('junit_app_path_relative_to_root') and Path(res).is_absolute():
885
+ try:
886
+ report_path = str(Path(res).resolve().relative_to(request.config.rootpath.resolve()))
887
+ except ValueError:
888
+ pass
889
+ record_xml_attribute('app_path', report_path)
877
890
  return res
878
891
 
879
892
 
@@ -153,6 +153,54 @@ def test_default_app_path(testdir):
153
153
  result.assert_outcomes(passed=1)
154
154
 
155
155
 
156
+ @pytest.mark.parametrize('enabled', [False, True])
157
+ def test_junit_app_path_relative_to_root(testdir, enabled):
158
+ root = Path(str(testdir.tmpdir))
159
+ app_paths = [str(root / 'components' / 'app'), str(root.parent / (root.name + '-other') / 'app'), 'relative/app']
160
+ if enabled:
161
+ testdir.makepyprojecttoml("""
162
+ [tool.pytest.ini_options]
163
+ junit_app_path_relative_to_root = true
164
+ junit_family = "xunit1"
165
+ """)
166
+ testdir.makepyfile(f"""
167
+ import pytest
168
+
169
+ @pytest.mark.parametrize('app_path', {app_paths!r}, indirect=True)
170
+ def test_app(app_path, request):
171
+ assert app_path == request.node.callspec.params['app_path']
172
+ """)
173
+
174
+ result = testdir.runpytest('--junitxml=result.xml')
175
+ result.assert_outcomes(passed=3)
176
+ assert [case.get('app_path') for case in ET.parse(root / 'result.xml').iter('testcase')] == [
177
+ 'components/app' if enabled else app_paths[0],
178
+ app_paths[1],
179
+ app_paths[2],
180
+ ]
181
+
182
+
183
+ def test_junit_app_path_uses_overridden_rootdir(testdir):
184
+ root = Path(str(testdir.tmpdir))
185
+ (root / 'project').mkdir()
186
+ testdir.makepyprojecttoml("""
187
+ [tool.pytest.ini_options]
188
+ junit_app_path_relative_to_root = true
189
+ junit_family = "xunit1"
190
+ """)
191
+ testdir.makepyfile(f"""
192
+ import pytest
193
+
194
+ @pytest.mark.parametrize('app_path', [{str(root / 'project/components/app')!r}], indirect=True)
195
+ def test_app(app_path):
196
+ pass
197
+ """)
198
+
199
+ result = testdir.runpytest('--rootdir=project', '--junitxml=result.xml')
200
+ result.assert_outcomes(passed=1)
201
+ assert [case.get('app_path') for case in ET.parse(root / 'result.xml').iter('testcase')] == ['components/app']
202
+
203
+
156
204
  @pytest.mark.parametrize(
157
205
  'parallel_count, parallel_index, res',
158
206
  [