diff --git a/mindspore/nn/cell.py b/mindspore/nn/cell.py index f2d91244e3..ed9a6925a1 100755 --- a/mindspore/nn/cell.py +++ b/mindspore/nn/cell.py @@ -315,6 +315,9 @@ class Cell(Cell_): return tuple(res) def __call__(self, *inputs, **kwargs): + if self.__class__.construct is Cell.construct: + logger.warning(f"The '{self.__class__}' does not override the method 'construct', " + f"will call the super class(Cell) 'construct'.") if kwargs: bound_args = inspect.signature(self.construct).bind(*inputs, **kwargs) inputs = bound_args.args @@ -681,7 +684,7 @@ class Cell(Cell_): Returns: Tensor, returns the computed result. """ - raise NotImplementedError + return None def init_parameters_data(self, auto_parallel_mode=False): """ diff --git a/tests/ut/python/nn/test_cell.py b/tests/ut/python/nn/test_cell.py index 0c46684039..f15cc5c65a 100644 --- a/tests/ut/python/nn/test_cell.py +++ b/tests/ut/python/nn/test_cell.py @@ -197,8 +197,7 @@ def test_exceptions(): ModError2(t) m = nn.Cell() - with pytest.raises(NotImplementedError): - m.construct() + assert m.construct() is None def test_cell_copy(): diff --git a/tests/ut/python/ops/test_ops_check.py b/tests/ut/python/ops/test_ops_check.py index beb1d4eb0f..3d19aef6d6 100644 --- a/tests/ut/python/ops/test_ops_check.py +++ b/tests/ut/python/ops/test_ops_check.py @@ -63,9 +63,7 @@ def test_net_without_construct(): """ test_net_without_construct """ net = NetMissConstruct() inp = Tensor(np.ones([1, 1, 32, 32]).astype(np.float32)) - with pytest.raises(RuntimeError) as err: - _executor.compile(net, inp) - assert "Unsupported syntax 'Raise' at " in str(err.value) + _executor.compile(net, inp) class NetWithRaise(nn.Cell): diff --git a/tests/ut/python/pipeline/parse/test_grammar_constraints.py b/tests/ut/python/pipeline/parse/test_grammar_constraints.py index d93a54039c..0343c93092 100644 --- a/tests/ut/python/pipeline/parse/test_grammar_constraints.py +++ b/tests/ut/python/pipeline/parse/test_grammar_constraints.py @@ -196,6 +196,4 @@ def test_missing_construct(): np_input = np.arange(2 * 3 * 4).reshape((2, 3, 4)).astype(np.bool_) tensor = Tensor(np_input) net = NetMissConstruct() - with pytest.raises(RuntimeError) as er: - net(tensor) - assert "Unsupported syntax 'Raise' at " in str(er.value) + assert net(tensor) is None diff --git a/tests/ut/python/pipeline/parse/test_super.py b/tests/ut/python/pipeline/parse/test_super.py index f8734584ad..d68fa5cb1c 100644 --- a/tests/ut/python/pipeline/parse/test_super.py +++ b/tests/ut/python/pipeline/parse/test_super.py @@ -14,7 +14,6 @@ # ============================================================================ """ test super""" import numpy as np -import pytest import mindspore.nn as nn from mindspore import Tensor @@ -108,9 +107,7 @@ def test_super_cell(): net = Net(2) x = Tensor(np.ones([1, 2, 3], np.int32)) y = Tensor(np.ones([1, 2, 3], np.int32)) - with pytest.raises(RuntimeError) as er: - net(x, y) - assert "Unsupported syntax 'Raise'" in str(er.value) + assert net(x, y) is None def test_single_super_in(): diff --git a/tests/ut/python/pynative_mode/nn/test_cell.py b/tests/ut/python/pynative_mode/nn/test_cell.py index ea052ef56d..9297670855 100644 --- a/tests/ut/python/pynative_mode/nn/test_cell.py +++ b/tests/ut/python/pynative_mode/nn/test_cell.py @@ -212,8 +212,7 @@ def test_exceptions(): ModError2(t) m = nn.Cell() - with pytest.raises(NotImplementedError): - m.construct() + assert m.construct() is None def test_del():