Skip to content

Commit 3eed689

Browse files
authored
Fix ptest for Python-pytest-forked (#13633)
1 parent d01712c commit 3eed689

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
From: Riken Maharjan <rmaharjan@microsoft.com>
2+
Date: Tue, 28 Apr 2025 10:00:00 -0700
3+
Subject: Fix Pytest Output issue for Forked Tests
4+
5+
diff --git a/testing/test_xfail_behavior.py b/testing/test_xfail_behavior.py
6+
index ef00385..15edd93 100644
7+
--- a/testing/test_xfail_behavior.py
8+
+++ b/testing/test_xfail_behavior.py
9+
@@ -6,6 +6,7 @@
10+
11+
IS_PYTEST4_PLUS = int(pytest.__version__[0]) >= 4 # noqa: WPS609
12+
FAILED_WORD = "FAILED" if IS_PYTEST4_PLUS else "FAIL"
13+
+PYTEST_GTE_7_2 = hasattr(pytest, "version_tuple") and pytest.version_tuple >= (7, 2) # type: ignore[attr-defined]
14+
15+
pytestmark = pytest.mark.skipif( # pylint: disable=invalid-name
16+
not hasattr(os, "fork"), # noqa: WPS421
17+
@@ -68,10 +69,12 @@ def test_xfail(is_crashing, is_strict, testdir):
18+
)
19+
)
20+
reason_string = (
21+
- " reason: The process gets terminated; "
22+
+ "reason: The process gets terminated; "
23+
"pytest-forked reason: "
24+
"*:*: running the test CRASHED with signal {sig_num:d}".format(**locals())
25+
)
26+
+ if expected_lowercase == "xfailed" and PYTEST_GTE_7_2:
27+
+ short_test_summary += " - " + reason_string
28+
total_summary_line = "*==== 1 {expected_lowercase!s} in 0.*s* ====*".format(
29+
**locals()
30+
)
31+
@@ -95,7 +98,7 @@ def test_xfail(is_crashing, is_strict, testdir):
32+
)
33+
if expected_lowercase == "xpassed" and expected_word == FAILED_WORD:
34+
# XPASS(strict)
35+
- expected_lines += (reason_string,)
36+
+ expected_lines += (" " + reason_string,)
37+
expected_lines += (total_summary_line,)
38+
39+
test_module = testdir.makepyfile(

SPECS/python-pytest-forked/python-pytest-forked.spec

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ C++ libraries that might crash the process. To use the plugin, simply use the
77
Summary: py.test plugin for running tests in isolated forked subprocesses
88
Name: python-%{pypi_name}
99
Version: 1.4.0
10-
Release: 2%{?dist}
10+
Release: 3%{?dist}
1111
License: MIT
1212
Vendor: Microsoft Corporation
1313
Distribution: Azure Linux
@@ -18,8 +18,10 @@ BuildRequires: python3-py
1818
BuildRequires: python3-setuptools
1919
BuildRequires: python3-setuptools_scm
2020
BuildArch: noarch
21+
Patch0: Pytest-Output-Fix.patch
2122
%if 0%{?with_check}
2223
BuildRequires: python3-pip
24+
BuildRequires: python3-pytest
2325
%endif
2426

2527
%description %{_description}
@@ -45,7 +47,6 @@ pip3 install atomicwrites>=1.3.0 \
4547
attrs>=19.1.0 \
4648
more-itertools>=7.0.0 \
4749
pluggy>=0.11.0 \
48-
pytest==7.1.2 \
4950
pytest-cov>=2.7.1
5051
PATH=%{buildroot}%{_bindir}:${PATH} \
5152
PYTHONPATH=%{buildroot}%{python3_sitelib} \
@@ -57,6 +58,9 @@ PYTHONPATH=%{buildroot}%{python3_sitelib} \
5758
%{python3_sitelib}/pytest_forked*
5859

5960
%changelog
61+
* Tue Apr 29 2025 Riken Maharjan <rmaharjan@microsoft.com> - 1.4.0-3
62+
- Add patch from upstream to account for new pytest output.
63+
6064
* Wed Oct 26 2022 Pawel Winogrodzki <pawelwi@microsoft.com> - 1.4.0-2
6165
- Freezing 'pytest' test dependency to version 7.1.2.
6266

0 commit comments

Comments
 (0)