Моя структура каталогов:
пакет
Код: Выделить всё
├── __init__.py
├── app.py
├── pytest.ini
├── sdtp
│ ├── __init__.py
│ ├── sdtp_filter.py
│ ├── sdtp_table.py
│ └── sdtp_utils.py
├── sdtp_server
│ ├── __init__.py
│ ├── sdtp_server.py
│ └── table_server.py
├── setup.cfg
├── setup.py
└── tests
├── __init__.py
├── conftest.py
├── pytest.ini
├── test_sdtp_filter.py
├── test_sdtp_server.py
├── test_sdtp_table.py
├── test_sdtp_table_and_filter.py
├── test_sdtp_utils.py
└── test_table_server.py
Код: Выделить всё
[pytest]
pythonpath = /workspaces/sdtp
Код: Выделить всё
#
# conftest.py
import sys
from os.path import dirname as d
from os.path import abspath, join
root_dir = d(d(abspath(__file__)))
sys.path.append(root_dir)
Код: Выделить всё
from sdtp.sdtp_utils import InvalidDataException
from sdtp.sdtp_utils import SDTP_BOOLEAN, SDTP_DATE, SDTP_DATETIME, SDTP_NUMBER, SDTP_PYTHON_TYPES, SDTP_SCHEMA_TYPES, SDTP_STRING, SDTP_TIME_OF_DAY
from sdtp.sdtp_utils import type_check, check_sdtp_type_of_list, jsonifiable_value, jsonifiable_row, jsonifiable_rows, jsonifiable_column, convert_to_type, convert_list_to_type, convert_row_to_type_list, convert_rows_to_type_list, convert_dict_to_type
from sdtp.sdtp_filter import SDTP_FILTER_OPERATORS, SDTP_FILTER_FIELDS, check_valid_spec, SDTPFilter
from sdtp.sdtp_table import SDTPTable, SDTPFixedTable, DataFrameTable, RowTable, RemoteCSVTable, RemoteSDTPTable
from sdtp_server.table_server import Table, TableServer, TableNotAuthorizedException, TableNotAuthorizedException, ColumnNotFoundException
from sdtp_server.table_server import build_table_spec
from sdtp_server.sdtp_server import sdtp_server_blueprint
Код: Выделить всё
vscode ➜ /workspaces/sdtp (main) $ pytest -vvv tests/test_sdtp_utils.py
ImportError while loading conftest '/workspaces/sdtp/tests/conftest.py'.
__init__.py:9: in
from sdtp.sdtp_utils import InvalidDataException
E ModuleNotFoundError: No module named 'sdtp.sdtp_utils'
Код: Выделить всё
import sys
print(sys.path)
Код: Выделить всё
['/workspaces', '/workspaces/sdtp', '/opt/conda/bin', '/opt/conda/lib/python311.zip', '/opt/conda/lib/python3.11', '/opt/conda/lib/python3.11/lib-dynload', '/opt/conda/lib/python3.11/site-packages']
Более того
Код: Выделить всё
$ python
> import __init__
> SDTP_BOOLEAN
'boolean'
Я добавил conftest.py и pytest.ini после прочтения ответов здесь: ModuleNotFoundError с pytest
Может кто-нибудь сказать мне, что происходит?
Я пробовал:
- Запуск собственного Python (работает нормально)
- Распечатка sys.path (получено то, что я ожидал)
- Добавление conftest.py и pytest.ini (без эффекта)
Подробнее здесь: https://stackoverflow.com/questions/786 ... -in-pytest