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

Unable to run pytest with platform linux -- Python 3.8.13, pytest-8.3.4, pluggy-1.5.0 #268

Closed
rushikeshjadhav opened this issue Jan 21, 2025 · 2 comments · Fixed by #269
Closed

Comments

@rushikeshjadhav
Copy link
Contributor

Ran into an error as below

[root@06371cf799bb xcp-ng-tests]# pytest tests/misc/test_vm_basic_operations.py --hosts=x.x.x.x
ImportError while loading conftest '/root/xcp-ng-tests/conftest.py'.
conftest.py:122: in <module>
    PHASE_REPORT_KEY = pytest.StashKey[dict[str, pytest.CollectReport]]()
E   TypeError: 'type' object is not subscriptable

Made changes to contest.py for it to work

[root@06371cf799bb xcp-ng-tests]# git diff
diff --git a/conftest.py b/conftest.py
index 3c176a4..bc562c4 100644
--- a/conftest.py
+++ b/conftest.py
@@ -119,7 +119,8 @@ def pytest_collection_modifyitems(items, config):
 # FIXME we may have to move this into lib/ if fixtures in sub-packages
 # want to make use of this feature
 
-PHASE_REPORT_KEY = pytest.StashKey[dict[str, pytest.CollectReport]]()
+from typing import Dict
+PHASE_REPORT_KEY = pytest.StashKey[Dict[str, pytest.CollectReport]]()
 @pytest.hookimpl(wrapper=True, tryfirst=True)
 def pytest_runtest_makereport(item, call):
     # execute all other hooks to obtain the report object

The type hint dict[str, pytest.CollectReport] uses subscripting ([]), which requires Python 3.9 or later for built-in types like dict.

Ref commit : 958e434

@stormi
Copy link
Member

stormi commented Jan 21, 2025

Indeed. IIRC we (@ydirson?) were going to either raise the requirement to python 3.8, or remove the need for subscripting.

@stormi
Copy link
Member

stormi commented Jan 21, 2025

I've got this local commit which works around the issue but I don't know if it's the best solution:

diff --git a/conftest.py b/conftest.py
index 2326774..45653ac 100644
--- a/conftest.py
+++ b/conftest.py
@@ -6,6 +6,7 @@ import pytest
 import tempfile
 
 from packaging import version
+from typing import Dict
 
 import lib.config as global_config
 
@@ -131,7 +132,7 @@ def pytest_collection_modifyitems(items, config):
 # FIXME we may have to move this into lib/ if fixtures in sub-packages
 # want to make use of this feature
 
-PHASE_REPORT_KEY = pytest.StashKey[dict[str, pytest.CollectReport]]()
+PHASE_REPORT_KEY = pytest.StashKey[Dict[str, pytest.CollectReport]]()
 @pytest.hookimpl(wrapper=True, tryfirst=True)
 def pytest_runtest_makereport(item, call):
     # execute all other hooks to obtain the report object

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