Skip to content

Commit e7d5aa7

Browse files
authored
👷 Tweak CI testing and fix import error detection for Python 3.8 (#8)
1 parent a97e902 commit e7d5aa7

File tree

7 files changed

+76
-68
lines changed

7 files changed

+76
-68
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ on:
1111
schedule:
1212
# cron every week on monday
1313
- cron: "0 0 * * 1"
14+
workflow_dispatch:
15+
inputs:
16+
number:
17+
description: PR number
18+
required: true
19+
debug_enabled:
20+
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
21+
required: false
22+
default: 'false'
1423

1524
jobs:
1625
test:
@@ -41,6 +50,12 @@ jobs:
4150
with:
4251
path: ${{ env.pythonLocation }}
4352
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}
53+
# Allow debugging with tmate
54+
- name: Setup tmate session
55+
uses: mxschmitt/action-tmate@v3
56+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
57+
with:
58+
limit-access-to-actor: true
4459
- name: Install Dependencies
4560
if: steps.cache.outputs.cache-hit != 'true'
4661
run: pip install -r requirements-tests.txt

src/fastapi_cli/discover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def get_module_data_from_path(path: Path) -> ModuleData:
101101
def get_app_name(*, mod_data: ModuleData, app_name: Union[str, None] = None) -> str:
102102
try:
103103
mod = importlib.import_module(mod_data.module_import_str)
104-
except ImportError as e:
104+
except (ImportError, ValueError) as e:
105105
logger.error(f"Import error: {e}")
106106
logger.warning(
107107
"Ensure all the package directories have an [blue]__init__.py[/blue] file"

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def reset_syspath() -> Generator[None, None, None]:
1616

1717

1818
@pytest.fixture(autouse=True, scope="session")
19-
def set_terminal_width() -> None:
19+
def setup_terminal() -> None:
2020
rich_utils.MAX_WIDTH = 3000
21+
rich_utils.FORCE_TERMINAL = False
2122
setup_logging(terminal_width=3000)
2223
return

tests/test_utils_default_dir.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ def test_app_dir_main(capsys: CaptureFixture[str]) -> None:
1919
assert "Using path app/main.py" in captured.out
2020
assert "Resolved absolute path" in captured.out
2121
assert (
22-
"/fastapi-cli/tests/assets/default_files/default_app_dir_main/app/main.py"
23-
in captured.out
22+
"/tests/assets/default_files/default_app_dir_main/app/main.py" in captured.out
2423
)
2524
assert "Importing from" in captured.out
26-
assert "fastapi-cli/tests/assets/default_files/default_app_dir_main" in captured.out
25+
assert "tests/assets/default_files/default_app_dir_main" in captured.out
2726
assert "╭─ Python package file structure ─╮" in captured.out
2827
assert "│ 📁 app" in captured.out
2928
assert "│ ├── 🐍 __init__.py" in captured.out
@@ -43,12 +42,9 @@ def test_app_dir_app(capsys: CaptureFixture[str]) -> None:
4342
captured = capsys.readouterr()
4443
assert "Using path app/app.py" in captured.out
4544
assert "Resolved absolute path" in captured.out
46-
assert (
47-
"/fastapi-cli/tests/assets/default_files/default_app_dir_app/app/app.py"
48-
in captured.out
49-
)
45+
assert "/tests/assets/default_files/default_app_dir_app/app/app.py" in captured.out
5046
assert "Importing from" in captured.out
51-
assert "fastapi-cli/tests/assets/default_files/default_app_dir_app" in captured.out
47+
assert "tests/assets/default_files/default_app_dir_app" in captured.out
5248
assert "╭─ Python package file structure ─╮" in captured.out
5349
assert "│ 📁 app" in captured.out
5450
assert "│ ├── 🐍 __init__.py" in captured.out
@@ -68,12 +64,9 @@ def test_app_dir_api(capsys: CaptureFixture[str]) -> None:
6864
captured = capsys.readouterr()
6965
assert "Using path app/api.py" in captured.out
7066
assert "Resolved absolute path" in captured.out
71-
assert (
72-
"/fastapi-cli/tests/assets/default_files/default_app_dir_api/app/api.py"
73-
in captured.out
74-
)
67+
assert "/tests/assets/default_files/default_app_dir_api/app/api.py" in captured.out
7568
assert "Importing from" in captured.out
76-
assert "fastapi-cli/tests/assets/default_files/default_app_dir_api" in captured.out
69+
assert "tests/assets/default_files/default_app_dir_api" in captured.out
7770
assert "╭─ Python package file structure ─╮" in captured.out
7871
assert "│ 📁 app" in captured.out
7972
assert "│ ├── 🐍 __init__.py" in captured.out

tests/test_utils_default_file.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@ def test_single_file_main(capsys: CaptureFixture[str]) -> None:
1717
old_sys_path = sys.path.copy()
1818
with changing_dir(root_path):
1919
sys.path.insert(0, str(root_path))
20-
app = importlib.import_module("app")
20+
mod = importlib.import_module("main")
2121

22-
importlib.reload(app)
22+
importlib.reload(mod)
2323
import_string = get_import_string()
2424
assert import_string == "main:app"
2525

2626
captured = capsys.readouterr()
2727
assert "Using path main.py" in captured.out
2828
assert "Resolved absolute path" in captured.out
29-
assert (
30-
"/fastapi-cli/tests/assets/default_files/default_main/main.py" in captured.out
31-
)
29+
assert "/tests/assets/default_files/default_main/main.py" in captured.out
3230
assert "Importing from" in captured.out
33-
assert "fastapi-cli/tests/assets/default_files/default_main" in captured.out
31+
assert "/tests/assets/default_files/default_main" in captured.out
3432
assert "╭─ Python module file ─╮" in captured.out
3533
assert "│ 🐍 main.py" in captured.out
3634
assert "Importing module main" in captured.out
@@ -46,18 +44,18 @@ def test_single_file_app(capsys: CaptureFixture[str]) -> None:
4644
old_sys_path = sys.path.copy()
4745
with changing_dir(root_path):
4846
sys.path.insert(0, str(root_path))
49-
app = importlib.import_module("app")
47+
mod = importlib.import_module("app")
5048

51-
importlib.reload(app)
49+
importlib.reload(mod)
5250
import_string = get_import_string()
5351
assert import_string == "app:app"
5452

5553
captured = capsys.readouterr()
5654
assert "Using path app.py" in captured.out
5755
assert "Resolved absolute path" in captured.out
58-
assert "/fastapi-cli/tests/assets/default_files/default_app/app.py" in captured.out
56+
assert "/tests/assets/default_files/default_app/app.py" in captured.out
5957
assert "Importing from" in captured.out
60-
assert "fastapi-cli/tests/assets/default_files/default_app" in captured.out
58+
assert "/tests/assets/default_files/default_app" in captured.out
6159
assert "╭─ Python module file ─╮" in captured.out
6260
assert "│ 🐍 app.py" in captured.out
6361
assert "Importing module app" in captured.out
@@ -73,18 +71,18 @@ def test_single_file_api(capsys: CaptureFixture[str]) -> None:
7371
old_sys_path = sys.path.copy()
7472
with changing_dir(root_path):
7573
sys.path.insert(0, str(root_path))
76-
app = importlib.import_module("app")
74+
mod = importlib.import_module("api")
7775

78-
importlib.reload(app)
76+
importlib.reload(mod)
7977
import_string = get_import_string()
8078
assert import_string == "api:app"
8179

8280
captured = capsys.readouterr()
8381
assert "Using path api.py" in captured.out
8482
assert "Resolved absolute path" in captured.out
85-
assert "/fastapi-cli/tests/assets/default_files/default_api/api.py" in captured.out
83+
assert "/tests/assets/default_files/default_api/api.py" in captured.out
8684
assert "Importing from" in captured.out
87-
assert "fastapi-cli/tests/assets/default_files/default_api" in captured.out
85+
assert "/tests/assets/default_files/default_api" in captured.out
8886
assert "╭─ Python module file ─╮" in captured.out
8987
assert "│ 🐍 api.py" in captured.out
9088
assert "Importing module api" in captured.out

0 commit comments

Comments
 (0)