A non-removable ModuleNotFoundError in pytest

I’ve been through the other answers, tried everything, and I’m still seeing this error.
My directory structure is:
package

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
├── __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
</code>
<code> ├── __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 </code>

├── __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.ini is

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[pytest]
pythonpath = /workspaces/sdtp
</code>
<code>[pytest] pythonpath = /workspaces/sdtp </code>
[pytest]
pythonpath = /workspaces/sdtp

conftest.py is:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#
# 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)
</code>
<code># # 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) </code>
#
# 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)

The root level init.py is:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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
</code>
<code>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 </code>
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

The error is:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>vscode ➜ /workspaces/sdtp (main) $ pytest -vvv tests/test_sdtp_utils.py
ImportError while loading conftest '/workspaces/sdtp/tests/conftest.py'.
__init__.py:9: in <module>
from sdtp.sdtp_utils import InvalidDataException
E ModuleNotFoundError: No module named 'sdtp.sdtp_utils'
</code>
<code>vscode ➜ /workspaces/sdtp (main) $ pytest -vvv tests/test_sdtp_utils.py ImportError while loading conftest '/workspaces/sdtp/tests/conftest.py'. __init__.py:9: in <module> from sdtp.sdtp_utils import InvalidDataException E ModuleNotFoundError: No module named 'sdtp.sdtp_utils' </code>
vscode ➜ /workspaces/sdtp (main) $ pytest -vvv tests/test_sdtp_utils.py
ImportError while loading conftest '/workspaces/sdtp/tests/conftest.py'.
__init__.py:9: in <module>
    from sdtp.sdtp_utils import InvalidDataException
E   ModuleNotFoundError: No module named 'sdtp.sdtp_utils'

Further, I added:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import sys
print(sys.path)
</code>
<code>import sys print(sys.path) </code>
import sys
print(sys.path)

to the init.py file (just before the ImportError) and got this result:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>['/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']
</code>
<code>['/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'] </code>
['/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']

the imports are in /workspaces/sdtp/sdtp, and that has an init.py file, so it’s (a) on the path; and (b) a module, and (c) it’s found just before the import error
Moreover

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>$ python
> import __init__
> SDTP_BOOLEAN
'boolean'
</code>
<code>$ python > import __init__ > SDTP_BOOLEAN 'boolean' </code>
$ python
> import __init__
> SDTP_BOOLEAN
'boolean'

works just fine, so when Python is run directly there is no ImportError.

I added conftest.py and pytest.ini after reading the answers here: ModuleNotFoundError with pytest

Can anyone tell me what’s going on?

I tried:

  1. Running python native (worked fine)
  2. Printing sys.path (got what I expected)
  3. Adding conftest.py and pytest.ini (no effect)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật