Skip to content

Commit aa6eb87

Browse files
committed
tests: split examples and pytests (#15774)
split examples and pytests (cherry picked from commit 952b64b)
1 parent 02e8f7b commit aa6eb87

File tree

8 files changed

+40
-36
lines changed

8 files changed

+40
-36
lines changed

.github/checkgroup.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ subprojects:
221221
- ".github/workflows/ci-app-tests.yml"
222222
- "src/lightning_app/**"
223223
- "tests/tests_app/**"
224-
- "examples/app_*/**" # some tests_app tests call examples files
225224
- "requirements/app/**"
226225
- "setup.py"
227226
- ".actions/**"

.github/workflows/ci-app-tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ on:
1111
- ".github/workflows/ci-app-tests.yml"
1212
- "src/lightning_app/**"
1313
- "tests/tests_app/**"
14-
- "examples/app_*/**" # some tests_app tests call examples files
1514
- "requirements/app/**"
1615
- "setup.py"
1716
- ".actions/**"

tests/tests_app/conftest.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,20 @@
33
import threading
44
from datetime import datetime
55
from pathlib import Path
6-
from subprocess import Popen
76

87
import psutil
98
import py
109
import pytest
11-
from tests_app import _PROJECT_ROOT
1210

1311
from lightning_app.storage.path import _storage_root_dir
1412
from lightning_app.utilities.component import _set_context
1513
from lightning_app.utilities.packaging import cloud_compute
1614
from lightning_app.utilities.packaging.app_config import _APP_CONFIG_FILENAME
1715
from lightning_app.utilities.state import AppState
1816

19-
GITHUB_APP_URLS = {
20-
"template_react_ui": "https://github.com/Lightning-AI/lightning-template-react.git",
21-
}
22-
2317
os.environ["LIGHTNING_DISPATCHED"] = "1"
2418

2519

26-
def pytest_sessionstart(*_):
27-
"""Pytest hook that get called after the Session object has been created and before performing collection and
28-
entering the run test loop."""
29-
for name, url in GITHUB_APP_URLS.items():
30-
if not os.path.exists(os.path.join(_PROJECT_ROOT, "examples", name)):
31-
path_examples = os.path.join(_PROJECT_ROOT, "examples")
32-
Popen(["git", "clone", url, name], cwd=path_examples).wait(timeout=90)
33-
else:
34-
Popen(["git", "pull", "main"], cwd=os.path.join(_PROJECT_ROOT, "examples", name)).wait(timeout=90)
35-
36-
3720
def pytest_sessionfinish(session, exitstatus):
3821
"""Pytest hook that get called after whole test run finished, right before returning the exit status to the
3922
system."""

tests/tests_app/runners/test_cloud.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@
4141
V1Work,
4242
)
4343

44-
from lightning_app import _PROJECT_ROOT, BuildConfig, LightningApp, LightningWork
44+
from lightning_app import BuildConfig, LightningApp, LightningWork
4545
from lightning_app.runners import backends, cloud, CloudRuntime
4646
from lightning_app.runners.cloud import (
4747
_generate_works_json_gallery,
4848
_generate_works_json_web,
4949
_validate_build_spec_and_compute,
5050
)
5151
from lightning_app.storage import Drive, Mount
52-
from lightning_app.testing.helpers import EmptyFlow, EmptyWork
52+
from lightning_app.testing.helpers import EmptyWork
5353
from lightning_app.utilities.cloud import _get_project
5454
from lightning_app.utilities.dependency_caching import get_hash
5555
from lightning_app.utilities.packaging.cloud_compute import CloudCompute
@@ -1222,16 +1222,6 @@ def test_project_has_sufficient_credits():
12221222
assert cloud_runtime._project_has_sufficient_credits(project) is result
12231223

12241224

1225-
@mock.patch(
1226-
"lightning_app.runners.cloud.load_app_from_file",
1227-
MagicMock(side_effect=ModuleNotFoundError("Module X not found")),
1228-
)
1229-
def test_load_app_from_file_module_error():
1230-
empty_app = CloudRuntime.load_app_from_file(os.path.join(_PROJECT_ROOT, "examples", "app_v0", "app.py"))
1231-
assert isinstance(empty_app, LightningApp)
1232-
assert isinstance(empty_app.root, EmptyFlow)
1233-
1234-
12351225
@pytest.mark.parametrize(
12361226
"lines",
12371227
[

tests/tests_app/utilities/test_load_app.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33

44
import pytest
55
import tests_app.core.scripts
6-
from tests_app import _PROJECT_ROOT
76

8-
from lightning_app import LightningApp
97
from lightning_app.utilities.exceptions import MisconfigurationException
108
from lightning_app.utilities.load_app import extract_metadata_from_app, load_app_from_file
119

1210

1311
def test_load_app_from_file():
14-
app = load_app_from_file(os.path.join(_PROJECT_ROOT, "examples", "app_v0", "app.py"))
15-
assert isinstance(app, LightningApp)
16-
1712
test_script_dir = os.path.join(os.path.dirname(tests_app.core.__file__), "scripts")
1813
with pytest.raises(MisconfigurationException, match="There should not be multiple apps instantiated within a file"):
1914
load_app_from_file(os.path.join(test_script_dir, "two_apps.py"))

tests/tests_app_examples/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
import os
22
import shutil
33
import threading
4+
from subprocess import Popen
45

56
import psutil
67
import pytest
78

9+
from lightning_app import _PROJECT_ROOT
810
from lightning_app.storage.path import _storage_root_dir
911
from lightning_app.utilities.component import _set_context
1012
from lightning_app.utilities.packaging import cloud_compute
1113
from lightning_app.utilities.packaging.app_config import _APP_CONFIG_FILENAME
1214
from lightning_app.utilities.state import AppState
1315

16+
GITHUB_APP_URLS = {
17+
"template_react_ui": "https://github.com/Lightning-AI/lightning-template-react.git",
18+
}
19+
1420
os.environ["LIGHTNING_DISPATCHED"] = "1"
1521

1622

23+
def pytest_sessionstart(*_):
24+
"""Pytest hook that get called after the Session object has been created and before performing collection and
25+
entering the run test loop."""
26+
for name, url in GITHUB_APP_URLS.items():
27+
if not os.path.exists(os.path.join(_PROJECT_ROOT, "examples", name)):
28+
path_examples = os.path.join(_PROJECT_ROOT, "examples")
29+
Popen(["git", "clone", url, name], cwd=path_examples).wait(timeout=90)
30+
else:
31+
Popen(["git", "pull", "main"], cwd=os.path.join(_PROJECT_ROOT, "examples", name)).wait(timeout=90)
32+
33+
1734
def pytest_sessionfinish(session, exitstatus):
1835
"""Pytest hook that get called after whole test run finished, right before returning the exit status to the
1936
system."""
File renamed without changes.

tests/tests_app_examples/test_v0_app.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import os
22
from time import sleep
33
from typing import Tuple
4+
from unittest import mock
5+
from unittest.mock import MagicMock
46

57
import pytest
68
from tests_app import _PROJECT_ROOT
79

10+
from lightning_app import LightningApp
11+
from lightning_app.runners import CloudRuntime
12+
from lightning_app.testing import EmptyFlow
813
from lightning_app.testing.testing import application_testing, LightningTestApp, run_app_in_cloud, wait_for
914
from lightning_app.utilities.enum import AppStage
15+
from lightning_app.utilities.load_app import load_app_from_file
1016

1117

1218
class LightningAppTestInt(LightningTestApp):
@@ -78,3 +84,18 @@ def test_v0_app_example_cloud() -> None:
7884
_,
7985
):
8086
run_v0_app(fetch_logs, view_page)
87+
88+
89+
@mock.patch(
90+
"lightning_app.runners.cloud.load_app_from_file",
91+
MagicMock(side_effect=ModuleNotFoundError("Module X not found")),
92+
)
93+
def test_load_app_from_file_module_error():
94+
empty_app = CloudRuntime.load_app_from_file(os.path.join(_PATH_EXAMPLES, "app_v0", "app.py"))
95+
assert isinstance(empty_app, LightningApp)
96+
assert isinstance(empty_app.root, EmptyFlow)
97+
98+
99+
def test_load_app_from_file():
100+
app = load_app_from_file(os.path.join(_PATH_EXAMPLES, "app_v0", "app.py"))
101+
assert isinstance(app, LightningApp)

0 commit comments

Comments
 (0)