1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414import time
15+ from unittest .mock import patch
1516
1617import pytest
1718
1819import pytorch_lightning .utilities .xla_device_utils as xla_utils
1920from pytorch_lightning .utilities import XLA_AVAILABLE , TPU_AVAILABLE
2021from tests .base .develop_utils import pl_multi_process_test
2122
22- if XLA_AVAILABLE :
23- import torch_xla .core .xla_model as xm
2423
25-
26- # lets hope that in or env we have installed XLA only for TPU devices, otherwise, it is testing in the cycle "if I am true test that I am true :D"
2724@pytest .mark .skipif (XLA_AVAILABLE , reason = "test requires torch_xla to be absent" )
2825def test_tpu_device_absence ():
2926 """Check tpu_device_exists returns None when torch_xla is not available"""
@@ -37,12 +34,12 @@ def test_tpu_device_presence():
3734 assert xla_utils .XLADeviceUtils .tpu_device_exists () is True
3835
3936
40- def test_result_returns_within_20_seconds ():
37+ @patch ('pytorch_lightning.utilities.xla_device_utils.TPU_CHECK_TIMEOUT' , 10 )
38+ def test_result_returns_within_timeout_seconds ():
4139 """Check that pl_multi_process returns within 10 seconds"""
42-
4340 start = time .time ()
44- result = xla_utils .pl_multi_process (time .sleep )(25 )
41+ result = xla_utils .pl_multi_process (time .sleep )(xla_utils . TPU_CHECK_TIMEOUT * 1. 25 )
4542 end = time .time ()
4643 elapsed_time = int (end - start )
47- assert elapsed_time <= 20
44+ assert elapsed_time <= xla_utils . TPU_CHECK_TIMEOUT
4845 assert result is False
0 commit comments