Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt_no_exception_capture = 0 is not working #576

Open
bersbersbers opened this issue Oct 21, 2024 · 2 comments
Open

qt_no_exception_capture = 0 is not working #576

bersbersbers opened this issue Oct 21, 2024 · 2 comments
Labels

Comments

@bersbersbers
Copy link

I have found that

def _is_exception_capture_enabled(item):
"""returns if exception capture is disabled for the given test item."""
disabled = get_marker(item, "qt_no_exception_capture") or item.config.getini(
"qt_no_exception_capture"
)
return not disabled

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 #573 (comment)

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
+
+@pytest.fixture(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
+
+@pytest.mark.qt_no_exception_capture
+def test_marker():
+    pass
+
+@pytest.mark.qt_no_exception_capture(0)
+def test_marker_zero():
+    pass
+
+@pytest.mark.qt_no_exception_capture(1)
+def test_marker_one():
+    pass
+
+@pytest.mark.qt_no_exception_capture(False)
+def test_marker_false():
+    pass
+
+@pytest.mark.qt_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
Copy link
Author

Also, I would argue that in the presence of qt_no_exception_capture = 1, pytest.mark.qt_no_exception_capture(0) and pytest.mark.qt_no_exception_capture(False) should allow overriding the global setting.

@nicoddemus
Copy link
Member

Thanks @bersbersbers indeed seems like a bug.

Also, I would argue that in the presence of qt_no_exception_capture = 1, pytest.mark.qt_no_exception_capture(0) and pytest.mark.qt_no_exception_capture(False) should allow overriding the global setting.

Agreed. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants