Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/pytorch_lightning/loggers/neptune.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,8 @@ def __init__(
agg_default_func: Optional[Callable[[Sequence[float]], float]] = None,
**neptune_run_kwargs: Any,
):
if neptune is None:
raise ModuleNotFoundError(
"You want to use the `Neptune` logger which is not installed yet, install it with"
" `pip install neptune-client`."
)
if not _NEPTUNE_AVAILABLE:
raise ModuleNotFoundError(str(_NEPTUNE_AVAILABLE))
# verify if user passed proper init arguments
self._verify_input_arguments(api_key, project, name, run, neptune_run_kwargs)
super().__init__(agg_key_funcs=agg_key_funcs, agg_default_func=agg_default_func)
Expand Down
5 changes: 4 additions & 1 deletion tests/tests_pytorch/loggers/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
mock.patch("pytorch_lightning.loggers.mlflow.mlflow"),
mock.patch("pytorch_lightning.loggers.mlflow.MlflowClient"),
mock.patch("pytorch_lightning.loggers.neptune.neptune", new_callable=create_neptune_mock),
mock.patch("pytorch_lightning.loggers.neptune._NEPTUNE_AVAILABLE", return_value=True),
mock.patch("pytorch_lightning.loggers.wandb.wandb"),
mock.patch("pytorch_lightning.loggers.wandb.Run", new=mock.Mock),
)
Expand Down Expand Up @@ -290,7 +291,9 @@ def test_logger_with_prefix_all(tmpdir, monkeypatch):
logger.experiment.log_metric.assert_called_once_with(ANY, "tmp-test", 1.0, ANY, 0)

# Neptune
with mock.patch("pytorch_lightning.loggers.neptune.neptune"):
with mock.patch("pytorch_lightning.loggers.neptune.neptune"), mock.patch(
"pytorch_lightning.loggers.neptune._NEPTUNE_AVAILABLE", return_value=True
):
logger = _instantiate_logger(NeptuneLogger, api_key="test", project="project", save_dir=tmpdir, prefix=prefix)
assert logger.experiment.__getitem__.call_count == 2
logger.log_metrics({"test": 1.0}, step=0)
Expand Down
5 changes: 5 additions & 0 deletions tests/tests_pytorch/loggers/test_neptune.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pickle
import unittest
from collections import namedtuple
from unittest import mock
from unittest.mock import call, MagicMock, patch

import pytest
Expand Down Expand Up @@ -78,6 +79,10 @@ def tmpdir_unittest_fixture(request, tmpdir):

@patch("pytorch_lightning.loggers.neptune.neptune", new_callable=create_neptune_mock)
class TestNeptuneLogger(unittest.TestCase):
def run(self, *args, **kwargs):
with mock.patch("pytorch_lightning.loggers.neptune._NEPTUNE_AVAILABLE", return_value=True):
super().run(*args, **kwargs)

def test_neptune_online(self, neptune):
logger = NeptuneLogger(api_key="test", project="project")
created_run_mock = logger.run
Expand Down