-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better check for programmatic lightningignore (#16080)
Co-authored-by: Jirka Borovec <[email protected]>
- Loading branch information
Showing
17 changed files
with
46 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
from lightning_app import _PROJECT_ROOT | ||
|
||
_PATH_APPS = os.path.join(_PROJECT_ROOT, "tests", "tests_examples_app", "apps") | ||
_PATH_APPS = Path(__file__).resolve().parents[1] / "apps" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
from lightning_app import _PROJECT_ROOT | ||
|
||
_PATH_EXAMPLES = os.path.join(_PROJECT_ROOT, "examples") | ||
_PATH_EXAMPLES = Path(__file__).resolve().parents[3] / "examples" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,47 @@ | ||
import os | ||
import sys | ||
from unittest import mock | ||
|
||
import pytest | ||
from lightning_utilities.core.imports import package_available | ||
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([w for w in self.works]) == 2 | ||
assert len(self.works) == 2 | ||
return True | ||
return res | ||
|
||
|
||
@pytest.mark.skip(reason="flaky") | ||
@mock.patch("lightning_app.components.multi_node.base.is_running_in_cloud", return_value=True) | ||
def test_multi_node_example(_, monkeypatch): | ||
monkeypatch.chdir(os.path.join(_PATH_EXAMPLES, "app_multi_node")) | ||
command_line = [ | ||
"app.py", | ||
"--blocking", | ||
"False", | ||
"--open-ui", | ||
"False", | ||
] | ||
result = application_testing(LightningTestMultiNodeApp, command_line) | ||
assert result.exit_code == 0 | ||
|
||
|
||
class LightningTestMultiNodeWorksApp(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([w for w in self.works]) == 2 | ||
return True | ||
return res | ||
# for the skip to work, the package needs to be installed without editable mode | ||
_SKIP_LIGHTNING_UNAVAILABLE = pytest.mark.skipif(not package_available("lightning"), reason="script requires lightning") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"app_name", | ||
[ | ||
"train_pytorch.py", | ||
"train_any.py", | ||
# "app_lite_work.py", | ||
"train_pytorch_spawn.py", | ||
# "app_pl_work.py": TODO Add once https://github.com/Lightning-AI/lightning/issues/15556 is resolved. | ||
pytest.param("train_lite.py", marks=_SKIP_LIGHTNING_UNAVAILABLE), | ||
pytest.param("train_lt_script.py", marks=_SKIP_LIGHTNING_UNAVAILABLE), | ||
pytest.param("train_lt.py", marks=_SKIP_LIGHTNING_UNAVAILABLE), | ||
], | ||
) | ||
@pytest.mark.skipif(sys.platform == "win32", reason="flaky") | ||
@_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(LightningTestMultiNodeWorksApp, command_line) | ||
result = application_testing(LightningTestMultiNodeApp, command_line) | ||
assert result.exit_code == 0 |