I have a python batch job where I require bigquery. While importing and working with the module, it working fine from application perspective. But when running pytest, I am not able to get the test running as it is not able to find the path.
/usr/local/lib/python3.10/pkgutil.py:417: in get_importer
importer = sys.path_importer_cache[path_item]
E KeyError: PosixPath('/somepath')
During handling of the above exception, another exception occurred:
/usr/local/lib/python3.10/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
???
<frozen importlib._bootstrap>:1027: in _find_and_load
???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:688: in _load_unlocked
???
/usr/local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
exec(co, module.__dict__)
src/common_utilities/bigquery_conn.py:1: in <module>
from google.cloud import bigquery
/usr/local/lib/python3.10/site-packages/google/cloud/bigquery/__init__.py:35: in <module>
from google.cloud.bigquery.client import Client
/usr/local/lib/python3.10/site-packages/google/cloud/bigquery/client.py:52: in <module>
import google.api_core.exceptions as core_exceptions
/usr/local/lib/python3.10/site-packages/google/api_core/exceptions.py:29: in <module>
from google.rpc import error_details_pb2
/usr/local/lib/python3.10/site-packages/google/rpc/__init__.py:18: in <module>
import pkg_resources
/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py:3260: in <module>
def _initialize_master_working_set():
/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py:3234: in _call_aside
f(*args, **kwargs)
/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py:3272: in _initialize_master_working_set
working_set = WorkingSet._build_master()
/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py:572: in _build_master
ws = cls()
/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py:565: in __init__
self.add_entry(entry)
/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py:621: in add_entry
for dist in find_distributions(entry, True):
/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py:1988: in find_distributions
importer = get_importer(path_item)
/usr/local/lib/python3.10/pkgutil.py:421: in get_importer
importer = path_hook(path_item)
<frozen importlib._bootstrap_external>:1632: in path_hook_for_FileFinder
???
<frozen importlib._bootstrap_external>:1504: in __init__
???
<frozen importlib._bootstrap_external>:182: in _path_isabs
???
E AttributeError: 'PosixPath' object has no attribute 'startswith'
When executed in local, the tests are running fine. Not able to find the right reason for error
New contributor
yogeshwarbabu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.