-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
test_multi_node.py
42 lines (36 loc) · 1.45 KB
/
test_multi_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
from unittest import mock
import pytest
from tests_examples_app.public import _PATH_EXAMPLES
from lightning_app.testing.helpers import _RunIf
from lightning_app.testing.testing import application_testing, LightningTestApp
class LightningTestMultiNodeApp(LightningTestApp):
def on_before_run_once(self):
res = super().on_before_run_once()
if self.works and all(w.has_stopped for w in self.works):
assert len(self.works) == 2
return True
return res
@pytest.mark.parametrize(
"app_name",
[
"train_lt_script.py",
"train_pytorch.py",
"train_any.py",
"train_lite.py",
"train_pytorch_spawn.py",
"train_lt.py",
],
)
@_RunIf(skip_windows=True) # flaky
@mock.patch("lightning_app.components.multi_node.base.is_running_in_cloud", return_value=True)
def test_multi_node_examples(_, app_name, monkeypatch):
# note: this test will fail locally:
# * if you installed `lightning_app`, then the examples need to be
# rewritten to use `lightning_app` imports (CI does this)
# * if you installed `lightning`, then the imports in this file and mocks
# need to be changed to use `lightning`.
monkeypatch.chdir(os.path.join(_PATH_EXAMPLES, "app_multi_node"))
command_line = [app_name, "--blocking", "False", "--open-ui", "False", "--setup"]
result = application_testing(LightningTestMultiNodeApp, command_line)
assert result.exit_code == 0