Skip to content

Commit b8bb64c

Browse files
committed
Skip tests that cause CLI argparse errors on Python 3.11.9 (#19756)
1 parent 3422101 commit b8bb64c

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

tests/tests_pytorch/loggers/test_wandb.py

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
from lightning.pytorch.utilities.exceptions import MisconfigurationException
2626
from lightning_utilities.test.warning import no_warning_call
2727

28+
from tests_pytorch.test_cli import _xfail_python_ge_3_11_9
29+
2830

2931
def test_wandb_project_name(wandb_mock):
3032
with mock.patch.dict(os.environ, {}):
@@ -548,6 +550,7 @@ def test_wandb_logger_download_artifact(wandb_mock, tmp_path):
548550
wandb_mock.Api().artifact.assert_called_once_with("test_artifact", type="model")
549551

550552

553+
@_xfail_python_ge_3_11_9
551554
@pytest.mark.parametrize(("log_model", "expected"), [("True", True), ("False", False), ("all", "all")])
552555
def test_wandb_logger_cli_integration(log_model, expected, wandb_mock, monkeypatch, tmp_path):
553556
"""Test that the WandbLogger can be used with the LightningCLI."""

tests/tests_pytorch/test_cli.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from lightning.pytorch.utilities.imports import _TORCHVISION_AVAILABLE
4949
from lightning_utilities import compare_version
5050
from lightning_utilities.test.warning import no_warning_call
51+
from packaging.version import Version
5152
from tensorboard.backend.event_processing import event_accumulator
5253
from tensorboard.plugins.hparams.plugin_data_pb2 import HParamsPluginData
5354
from torch.optim import SGD
@@ -64,6 +65,14 @@ def lazy_instance(*args, **kwargs):
6465
return None
6566

6667

68+
_xfail_python_ge_3_11_9 = pytest.mark.xfail(
69+
# https://github.com/omni-us/jsonargparse/issues/484
70+
Version(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}") >= Version("3.11.9"),
71+
strict=False,
72+
reason="jsonargparse + Python 3.11.9 compatibility issue",
73+
)
74+
75+
6776
@contextmanager
6877
def mock_subclasses(baseclass, *subclasses):
6978
"""Mocks baseclass so that it only has the given child subclasses."""
@@ -347,6 +356,7 @@ def test_save_to_log_dir_false_error():
347356
)
348357

349358

359+
@_xfail_python_ge_3_11_9
350360
def test_lightning_cli_logger_save_config(cleandir):
351361
class LoggerSaveConfigCallback(SaveConfigCallback):
352362
def __init__(self, *args, **kwargs) -> None:
@@ -736,6 +746,7 @@ def add_arguments_to_parser(self, parser):
736746
assert cli.trainer.lr_scheduler_configs[0].scheduler.step_size == 50
737747

738748

749+
@_xfail_python_ge_3_11_9
739750
@pytest.mark.parametrize("use_generic_base_class", [False, True])
740751
def test_lightning_cli_optimizers_and_lr_scheduler_with_link_to(use_generic_base_class):
741752
class MyLightningCLI(LightningCLI):
@@ -782,7 +793,7 @@ def __init__(self, optim1: dict, optim2: dict, scheduler: dict):
782793
assert isinstance(cli.model.scheduler, torch.optim.lr_scheduler.ExponentialLR)
783794

784795

785-
@pytest.mark.skipif(compare_version("jsonargparse", operator.lt, "4.21.3"), reason="vulnerability with failing imports")
796+
@_xfail_python_ge_3_11_9
786797
def test_lightning_cli_optimizers_and_lr_scheduler_with_callable_type():
787798
class TestModel(BoringModel):
788799
def __init__(
@@ -953,6 +964,7 @@ def __init__(self, foo, bar=5):
953964
self.bar = bar
954965

955966

967+
@_xfail_python_ge_3_11_9
956968
def test_lightning_cli_model_short_arguments():
957969
with mock.patch("sys.argv", ["any.py", "fit", "--model=BoringModel"]), mock.patch(
958970
"lightning.pytorch.Trainer._fit_impl"
@@ -977,6 +989,7 @@ def __init__(self, foo, bar=5):
977989
self.bar = bar
978990

979991

992+
@_xfail_python_ge_3_11_9
980993
def test_lightning_cli_datamodule_short_arguments():
981994
# with set model
982995
with mock.patch("sys.argv", ["any.py", "fit", "--data=BoringDataModule"]), mock.patch(
@@ -1022,6 +1035,7 @@ def test_lightning_cli_datamodule_short_arguments():
10221035
assert cli.parser.groups["data"].group_class is BoringDataModule
10231036

10241037

1038+
@_xfail_python_ge_3_11_9
10251039
@pytest.mark.parametrize("use_class_path_callbacks", [False, True])
10261040
def test_callbacks_append(use_class_path_callbacks):
10271041
"""This test validates registries are used when simplified command line are being used."""
@@ -1065,6 +1079,7 @@ def test_callbacks_append(use_class_path_callbacks):
10651079
assert all(t in callback_types for t in expected)
10661080

10671081

1082+
@_xfail_python_ge_3_11_9
10681083
def test_optimizers_and_lr_schedulers_reload(cleandir):
10691084
base = ["any.py", "--trainer.max_epochs=1"]
10701085
input = base + [
@@ -1096,6 +1111,7 @@ def test_optimizers_and_lr_schedulers_reload(cleandir):
10961111
LightningCLI(BoringModel, run=False)
10971112

10981113

1114+
@_xfail_python_ge_3_11_9
10991115
def test_optimizers_and_lr_schedulers_add_arguments_to_parser_implemented_reload(cleandir):
11001116
class TestLightningCLI(LightningCLI):
11011117
def __init__(self, *args):
@@ -1349,6 +1365,7 @@ def test_cli_help_message():
13491365
assert "Implements Adam" in shorthand_help.getvalue()
13501366

13511367

1368+
@_xfail_python_ge_3_11_9
13521369
def test_cli_reducelronplateau():
13531370
with mock.patch(
13541371
"sys.argv", ["any.py", "--optimizer=Adam", "--lr_scheduler=ReduceLROnPlateau", "--lr_scheduler.monitor=foo"]
@@ -1359,6 +1376,7 @@ def test_cli_reducelronplateau():
13591376
assert config["lr_scheduler"]["scheduler"].monitor == "foo"
13601377

13611378

1379+
@_xfail_python_ge_3_11_9
13621380
def test_cli_configureoptimizers_can_be_overridden():
13631381
class MyCLI(LightningCLI):
13641382
def __init__(self):
@@ -1403,6 +1421,7 @@ def __init__(self, activation: torch.nn.Module = lazy_instance(torch.nn.LeakyReL
14031421
assert cli.model.activation is not model.activation
14041422

14051423

1424+
@_xfail_python_ge_3_11_9
14061425
def test_ddpstrategy_instantiation_and_find_unused_parameters(mps_count_0):
14071426
strategy_default = lazy_instance(DDPStrategy, find_unused_parameters=True)
14081427
with mock.patch("sys.argv", ["any.py", "--trainer.strategy.process_group_backend=group"]):
@@ -1418,6 +1437,7 @@ def test_ddpstrategy_instantiation_and_find_unused_parameters(mps_count_0):
14181437
assert strategy_default is not cli.config_init.trainer.strategy
14191438

14201439

1440+
@_xfail_python_ge_3_11_9
14211441
def test_cli_logger_shorthand():
14221442
with mock.patch("sys.argv", ["any.py"]):
14231443
cli = LightningCLI(TestModel, run=False, trainer_defaults={"logger": False})
@@ -1448,6 +1468,7 @@ def _test_logger_init_args(logger_name, init, unresolved=None):
14481468
assert data["dict_kwargs"] == unresolved
14491469

14501470

1471+
@_xfail_python_ge_3_11_9
14511472
def test_comet_logger_init_args():
14521473
_test_logger_init_args(
14531474
"CometLogger",
@@ -1463,6 +1484,7 @@ def test_comet_logger_init_args():
14631484
strict=False,
14641485
reason="TypeError on Windows when parsing",
14651486
)
1487+
@_xfail_python_ge_3_11_9
14661488
def test_neptune_logger_init_args():
14671489
_test_logger_init_args(
14681490
"NeptuneLogger",
@@ -1471,6 +1493,7 @@ def test_neptune_logger_init_args():
14711493
)
14721494

14731495

1496+
@_xfail_python_ge_3_11_9
14741497
def test_tensorboard_logger_init_args():
14751498
_test_logger_init_args(
14761499
"TensorBoardLogger",
@@ -1482,6 +1505,7 @@ def test_tensorboard_logger_init_args():
14821505
)
14831506

14841507

1508+
@_xfail_python_ge_3_11_9
14851509
def test_wandb_logger_init_args():
14861510
_test_logger_init_args(
14871511
"WandbLogger",
@@ -1566,6 +1590,7 @@ def __init__(self, a_func: Callable = torch.nn.Softmax):
15661590
assert "a_func: torch.nn.Softmax" in out.getvalue()
15671591

15681592

1593+
@_xfail_python_ge_3_11_9
15691594
def test_pytorch_profiler_init_args():
15701595
from lightning.pytorch.profilers import Profiler, PyTorchProfiler
15711596

0 commit comments

Comments
 (0)