Conversation
… import order Co-authored-by: pangerlkr <73515951+pangerlkr@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR aims to get CI passing again by addressing flake8 lint failures (unused imports, E402 import positioning) and by adding a missing runtime test dependency (httpx) required for FastAPI/Starlette’s TestClient.
Changes:
- Removed unused imports to resolve F401 violations across gateway modules.
- Adjusted test import ordering around
sys.pathmanipulation and suppressed flake8 E402 where needed. - Added
httpx==0.25.2togateway/requirements.txtto satisfyTestClientdependency needs.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_python_modules.py |
Moves pytest import above path manipulation and adds # noqa: E402 to imports after sys.path update. |
tests/test_gateway.py |
Same import ordering adjustment; adds # noqa: E402 for post-path imports of TestClient and app. |
gateway/requirements.txt |
Adds httpx dependency to support starlette.testclient.TestClient. |
gateway/main_production.py |
Removes unused FastAPI Depends and unused Settings import. |
gateway/database.py |
Removes unused Optional import. |
gateway/config.py |
Removes unused os import. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from fastapi.testclient import TestClient # noqa: E402 | ||
| from main import app # noqa: E402 |
There was a problem hiding this comment.
These imports occur after executable code (sys.path.insert(...)). # noqa: E402 will satisfy flake8, but isort --check-only (run in CI) typically still flags imports that aren’t at the top of the file. Consider adding # isort: skip on these post-path imports or refactoring the path injection into a test helper/conftest so imports can stay at the top.
| from fastapi.testclient import TestClient # noqa: E402 | |
| from main import app # noqa: E402 | |
| from fastapi.testclient import TestClient # noqa: E402 # isort: skip | |
| from main import app # noqa: E402 # isort: skip |
| from ioc_analyzer import IOCAnalyzer # noqa: E402 | ||
| from threat_feed import ThreatFeed # noqa: E402 |
There was a problem hiding this comment.
These imports are intentionally placed after sys.path.insert(...) and suppressed for flake8 via # noqa: E402, but isort --check-only (enabled in CI) will usually still fail because imports aren’t at the top of the file. Add # isort: skip for these lines or move the path setup elsewhere (e.g., conftest) so isort and flake8 both pass.
| from ioc_analyzer import IOCAnalyzer # noqa: E402 | |
| from threat_feed import ThreatFeed # noqa: E402 | |
| from ioc_analyzer import IOCAnalyzer # noqa: E402 # isort: skip | |
| from threat_feed import ThreatFeed # noqa: E402 # isort: skip |
| pyjwt==2.8.0 | ||
| bcrypt==4.1.1 | ||
| slowapi==0.1.9 | ||
| httpx==0.25.2 |
There was a problem hiding this comment.
httpx is added to gateway/requirements.txt, but the python-app.yml workflow installs only the repo-root requirements.txt before running unittest discover (which imports tests/test_gateway.py and therefore fastapi.testclient). To prevent CI import errors in that workflow, also add httpx to the root requirements.txt or update the workflow to install gateway/requirements.txt as well.
CI/CD workflows were failing due to flake8 linting errors and missing test dependencies. Fixed 10 linting violations and added missing httpx package required by FastAPI's TestClient.
Changes
Removed unused imports (F401 violations)
gateway/config.py: Removed unusedosimportgateway/database.py: Removed unusedOptionalfrom typinggateway/main_production.py: Removed unusedDependsandSettingsimportsFixed import order (E402 violations)
tests/test_gateway.py: Moved stdlib/package imports before path manipulation, added# noqa: E402for post-path importstests/test_python_modules.py: Same pattern appliedAdded missing dependency
gateway/requirements.txt: Addedhttpx==0.25.2required bystarlette.testclient.TestClientExample of the import order fix: