You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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.
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
Ran into an error as below
Made changes to
contest.py
for it to workThe type hint
dict[str, pytest.CollectReport]
uses subscripting ([]), which requires Python 3.9 or later for built-in types like dict.Ref commit : 958e434
The text was updated successfully, but these errors were encountered: