-
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.
Ignore
num_nodes
when running MultiNode components locally (#15806)
- Loading branch information
Showing
6 changed files
with
68 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from re import escape | ||
|
||
import pytest | ||
from tests_app.helpers.utils import no_warning_call | ||
|
||
from lightning_app import CloudCompute, LightningWork | ||
from lightning_app.components import MultiNode | ||
|
||
|
||
def test_multi_node_warn_running_locally(): | ||
class Work(LightningWork): | ||
def run(self): | ||
pass | ||
|
||
with pytest.warns(UserWarning, match=escape("You set MultiNode(num_nodes=1, ...)` but ")): | ||
MultiNode(Work, num_nodes=2, cloud_compute=CloudCompute("gpu")) | ||
|
||
with no_warning_call(UserWarning, match=escape("You set MultiNode(num_nodes=1, ...)` but ")): | ||
MultiNode(Work, num_nodes=1, cloud_compute=CloudCompute("gpu")) |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import re | ||
from contextlib import contextmanager | ||
from typing import Optional, Type | ||
|
||
import pytest | ||
|
||
|
||
@contextmanager | ||
def no_warning_call(expected_warning: Type[Warning] = UserWarning, match: Optional[str] = None): | ||
# TODO: Replace with `lightning_utilities.test.warning.no_warning_call` | ||
# https://github.com/Lightning-AI/utilities/issues/57 | ||
|
||
with pytest.warns(None) as record: | ||
yield | ||
|
||
if match is None: | ||
try: | ||
w = record.pop(expected_warning) | ||
except AssertionError: | ||
# no warning raised | ||
return | ||
else: | ||
for w in record.list: | ||
if w.category is expected_warning and re.compile(match).search(w.message.args[0]): | ||
break | ||
else: | ||
return | ||
|
||
msg = "A warning" if expected_warning is None else f"`{expected_warning.__name__}`" | ||
raise AssertionError(f"{msg} was raised: {w}") |
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