I’m working on a multi-component machine learning project with a Flask API and complex model loading mechanisms.
I’m experiencing an unexpected error when running pytest that prevents model initialization. Interestingly, the API works fine when used outside of pytest.
Error Details python ERROR MyLogger:app.py:97 Unexpected error loading models: Can't get attribute 'Classifier' on <module 'pytest.main' from '/path/to/pytest/main.py'>
Key Points
- The API functions correctly when used normally (outside of pytest) The error only occurs during pytest execution
- The relevant files are:
- Model code:
scripts/classif/model_image.py
- API code:
app/webapp/app.py
- Test file:
tests/test_api.py
- Model code:
- In
app/webapp/app.py
, I’m importingscripts.classif.model_image
and using a class from it - The issue seems to be related to how pytest interacts with the model loading process
- My pyproject.toml file includes the following pytest configuration:
[tool.pytest.ini_options] pythonpath = [ "." ]
Project Structure
├── Makefile ├── README.md ├── app │ ├── frontend │ │ ├── app.py │ ├── logger_config.py │ └── webapp │ │ ├── app.py ├── models │ ├── bert_finetuned_model │ ├── bert_finetuned_model_content │ ├── tokenizer │ └── yolo ├── scripts │ ├── classif │ │ ├── init .py │ │ ├── cnn.py │ │ └── model_image.py ├── tests │ ├── test_api.py │ └── test_image.jpg ├── requirements.txt └── pyproject.toml
Environment
- Python 3.11
- Flask
- Pytest 8.3.4
- Custom ML models
Would appreciate any insights or suggestions on resolving this pytest-specific issue while maintaining normal functionality!
submitted by /u/Gogzli
[link] [comments]
r/learnpython I’m working on a multi-component machine learning project with a Flask API and complex model loading mechanisms. I’m experiencing an unexpected error when running pytest that prevents model initialization. Interestingly, the API works fine when used outside of pytest. Error Details python ERROR MyLogger:app.py:97 Unexpected error loading models: Can’t get attribute ‘Classifier’ on <module ‘pytest.main’ from ‘/path/to/pytest/main.py’> Key Points The API functions correctly when used normally (outside of pytest) The error only occurs during pytest execution The relevant files are: Model code: scripts/classif/model_image.py API code: app/webapp/app.py Test file: tests/test_api.py In app/webapp/app.py, I’m importing scripts.classif.model_image and using a class from it The issue seems to be related to how pytest interacts with the model loading process My pyproject.toml file includes the following pytest configuration: [tool.pytest.ini_options] pythonpath = [ “.” ] Project Structure ├── Makefile ├── README.md ├── app │ ├── frontend │ │ ├── app.py │ ├── logger_config.py │ └── webapp │ │ ├── app.py ├── models │ ├── bert_finetuned_model │ ├── bert_finetuned_model_content │ ├── tokenizer │ └── yolo ├── scripts │ ├── classif │ │ ├── init .py │ │ ├── cnn.py │ │ └── model_image.py ├── tests │ ├── test_api.py │ └── test_image.jpg ├── requirements.txt └── pyproject.toml Environment Python 3.11 Flask Pytest 8.3.4 Custom ML models Would appreciate any insights or suggestions on resolving this pytest-specific issue while maintaining normal functionality! submitted by /u/Gogzli [link] [comments]
I’m working on a multi-component machine learning project with a Flask API and complex model loading mechanisms.
I’m experiencing an unexpected error when running pytest that prevents model initialization. Interestingly, the API works fine when used outside of pytest.
Error Details python ERROR MyLogger:app.py:97 Unexpected error loading models: Can't get attribute 'Classifier' on <module 'pytest.main' from '/path/to/pytest/main.py'>
Key Points
- The API functions correctly when used normally (outside of pytest) The error only occurs during pytest execution
- The relevant files are:
- Model code:
scripts/classif/model_image.py
- API code:
app/webapp/app.py
- Test file:
tests/test_api.py
- Model code:
- In
app/webapp/app.py
, I’m importingscripts.classif.model_image
and using a class from it - The issue seems to be related to how pytest interacts with the model loading process
- My pyproject.toml file includes the following pytest configuration:
[tool.pytest.ini_options] pythonpath = [ "." ]
Project Structure
├── Makefile ├── README.md ├── app │ ├── frontend │ │ ├── app.py │ ├── logger_config.py │ └── webapp │ │ ├── app.py ├── models │ ├── bert_finetuned_model │ ├── bert_finetuned_model_content │ ├── tokenizer │ └── yolo ├── scripts │ ├── classif │ │ ├── init .py │ │ ├── cnn.py │ │ └── model_image.py ├── tests │ ├── test_api.py │ └── test_image.jpg ├── requirements.txt └── pyproject.toml
Environment
- Python 3.11
- Flask
- Pytest 8.3.4
- Custom ML models
Would appreciate any insights or suggestions on resolving this pytest-specific issue while maintaining normal functionality!
submitted by /u/Gogzli
[link] [comments]