Title: Pytest issues · Issue #44 · whythawk/full-stack-fastapi-postgresql · GitHub
Open Graph Title: Pytest issues · Issue #44 · whythawk/full-stack-fastapi-postgresql
X Title: Pytest issues · Issue #44 · whythawk/full-stack-fastapi-postgresql
Description: Been having a ton of trouble running the scripts/test-local.sh as instructed in the README. I keep running into ModulenotFoundError issues in backend/app/app/tests/conftest.py I've confirmed the following are working: My backend Docker c...
Open Graph Description: Been having a ton of trouble running the scripts/test-local.sh as instructed in the README. I keep running into ModulenotFoundError issues in backend/app/app/tests/conftest.py I've confirmed the fo...
X Description: Been having a ton of trouble running the scripts/test-local.sh as instructed in the README. I keep running into ModulenotFoundError issues in backend/app/app/tests/conftest.py I've confirmed th...
Opengraph URL: https://github.com/whythawk/full-stack-fastapi-postgresql/issues/44
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Pytest issues","articleBody":"Been having a ton of trouble running the `scripts/test-local.sh` as instructed in the `README`. I keep running into `ModulenotFoundError` issues in `backend/app/app/tests/conftest.py` I've confirmed the following are working:\r\n\r\n1. My backend Docker container is copying over `backend/app` to `/app` as expected.\r\n2. `/app` is getting set as the Python path as expected.\r\n3. Imports work normally when `bash`'d into the backend container.\r\n4. Imports work normally when running the backend service.\r\n5. `sys.path` contains `/app` as expected (I print it out while running `pytest -s`).\r\n\r\nHowever, no matter how I seem to run `pytest` (`bash`'d into the backend service, `docker compose run backend pytest`, or the `test-local.sh` script), I get the following error:\r\n\r\n```\r\n==================================================================================================== ERRORS ====================================================================================================\r\n________________________________________________________________________________________ ERROR collecting test session _________________________________________________________________________________________\r\n/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py:641: in _importconftest\r\n mod = import_path(conftestpath, mode=importmode, root=rootpath)\r\n/usr/local/lib/python3.10/site-packages/_pytest/pathlib.py:567: in import_path\r\n importlib.import_module(module_name)\r\n/usr/local/lib/python3.10/importlib/__init__.py:126: in import_module\r\n return _bootstrap._gcd_import(name[level:], package, level)\r\n\u003cfrozen importlib._bootstrap\u003e:1050: in _gcd_import\r\n ???\r\n\u003cfrozen importlib._bootstrap\u003e:1027: in _find_and_load\r\n ???\r\n\u003cfrozen importlib._bootstrap\u003e:1006: in _find_and_load_unlocked\r\n ???\r\n\u003cfrozen importlib._bootstrap\u003e:688: in _load_unlocked\r\n ???\r\n/usr/local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:186: in exec_module\r\n exec(co, module.__dict__)\r\napp/tests/conftest.py:14: in \u003cmodule\u003e\r\n from app.core.config import settings\r\nE ModuleNotFoundError: No module named 'app.core'\r\n```\r\n\r\nWhen I try to append an extra `app.` to the imports (e.g., `from app.app.core.config import settings`, the error goes away, but then my regular backend service crashes (ModuleNotFoundError `app.app`). Clearly it is some difference between how pytest and running the service regularly handle imports.\r\n\r\nMy file structure is the same as the template project: the `main.py` for FastAPI lives at `backend/app/app`, my `pyproject.toml` lives at `backend/app`. \r\n\r\nI am running `pytest 7.1.3`, `python 3.10`, and Mac OS 14.1. \r\n","author":{"url":"https://github.com/jmwebb","@type":"Person","name":"jmwebb"},"datePublished":"2023-12-12T05:52:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/44/full-stack-fastapi-postgresql/issues/44"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f4361a16-8be7-b3c8-7e86-135e887cba59 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D742:113E13:5C9FAC:791E61:698E5D53 |
| html-safe-nonce | cccbe6d802ed4d767f1ef4ac4d0d77689dadeec43c8ba7bb26672cac52bc4106 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzQyOjExM0UxMzo1QzlGQUM6NzkxRTYxOjY5OEU1RDUzIiwidmlzaXRvcl9pZCI6Ijg0MzQxMTIxMDIyMzUyNjYzODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 84fee41ded62ed89cf539380fd9437e272cc9cae4b688ea91de00cc8d4afcb1a |
| hovercard-subject-tag | issue:2037034248 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/whythawk/full-stack-fastapi-postgresql/44/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ad14d039eed76d9ea1111b4f0f9bf341e437667b502a4e40e29f51dd6d33e982/whythawk/full-stack-fastapi-postgresql/issues/44 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ad14d039eed76d9ea1111b4f0f9bf341e437667b502a4e40e29f51dd6d33e982/whythawk/full-stack-fastapi-postgresql/issues/44 |
| og:image:alt | Been having a ton of trouble running the scripts/test-local.sh as instructed in the README. I keep running into ModulenotFoundError issues in backend/app/app/tests/conftest.py I've confirmed the fo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jmwebb |
| hostname | github.com |
| expected-hostname | github.com |
| None | 666e30cc1de8ebdf458084bf731e95deba4f074a5008f91b50803aa9a71e3725 |
| turbo-cache-control | no-preview |
| go-import | github.com/whythawk/full-stack-fastapi-postgresql git https://github.com/whythawk/full-stack-fastapi-postgresql.git |
| octolytics-dimension-user_id | 7559868 |
| octolytics-dimension-user_login | whythawk |
| octolytics-dimension-repository_id | 385291678 |
| octolytics-dimension-repository_nwo | whythawk/full-stack-fastapi-postgresql |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 172227885 |
| octolytics-dimension-repository_parent_nwo | fastapi/full-stack-fastapi-template |
| octolytics-dimension-repository_network_root_id | 172227885 |
| octolytics-dimension-repository_network_root_nwo | fastapi/full-stack-fastapi-template |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f2d67bd549813f8aceb31f205ebdb434e9d46d38 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width