pytest-qt icon indicating copy to clipboard operation
pytest-qt copied to clipboard

`qt_no_exception_capture = 0` is not working

Open bersbersbers opened this issue 4 months ago • 2 comments

I have found that

https://github.com/pytest-dev/pytest-qt/blob/cdad310e88bcabe0cd6eb21843125b43706b54f1/src/pytestqt/exceptions.py#L90-L95

always returns False because disabled is either "0" or "1" (as strings) or Mark(...), depending on whether I use pytest.mark.qt_no_exception_capture or qt_no_exception_capture = 1, all of which evaluate to True.

Originally posted by @bersbersbers in https://github.com/pytest-dev/pytest-qt/issues/573#issuecomment-2412981118

Example code:

diff --git a/pytest.ini b/pytest.ini
index 9ade678..2c1ef1e 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -4,3 +4,4 @@ addopts = --strict-markers --strict-config
 xfail_strict = true
 markers =
   filterwarnings: pytest's filterwarnings marker
+qt_no_exception_capture = 0
diff --git a/src/pytestqt/exceptions.py b/src/pytestqt/exceptions.py
index d342876..afbd5c5 100644
--- a/src/pytestqt/exceptions.py
+++ b/src/pytestqt/exceptions.py
@@ -92,6 +92,7 @@ def _is_exception_capture_enabled(item):
     disabled = get_marker(item, "qt_no_exception_capture") or item.config.getini(
         "qt_no_exception_capture"
     )
+    print(not disabled)
     return not disabled


diff --git a/tests/test_bug.py b/tests/test_bug.py
new file mode 100644
index 0000000..8008047
--- /dev/null
+++ b/tests/test_bug.py
@@ -0,0 +1,32 @@
+import pytest
+from pytestqt.exceptions import _is_exception_capture_enabled
+
[email protected](scope="session", autouse=True)
+def check_is_exception_capture_enabled(request):
+    session = request.node
+    for item in session.items:
+        print(_is_exception_capture_enabled(item))
+
+def test_nomarker():
+    pass
+
[email protected]_no_exception_capture
+def test_marker():
+    pass
+
[email protected]_no_exception_capture(0)
+def test_marker_zero():
+    pass
+
[email protected]_no_exception_capture(1)
+def test_marker_one():
+    pass
+
[email protected]_no_exception_capture(False)
+def test_marker_false():
+    pass
+
[email protected]_no_exception_capture(True)
+def test_marker_true():
+    pass
+

Then run pip install -e . && pytest -s tests\test_bug.py and see all False.

bersbersbers avatar Oct 21 '24 07:10 bersbersbers