Repository: cupy/cupy

Issue:
Remove mock from test requirements?
I'm learning how to write mock tests, and I noticed things like `import mock` are workarounds to support PY27 and older PY3. Since CuPy now support PY35+ only and `mock` becomes part of the standard Python library, I suppose this line is no longer needed:
https://github.com/cupy/cupy/blob/74dcb4172578a0771e06f4e44b10b5f73f68fb59/setup.py#L39
and all `import mock` can be replaced by `from unittest import mock`?


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -36,7 +36,6 @@
     'test': [
         'pytest<4.2.0',  # 4.2.0 is slow collecting tests and times out on CI.
         'attrs<19.2.0',  # pytest 4.1.1 does not run with attrs==19.2.0
-        'mock',
     ],
     'doctest': [
         'matplotlib',


Test patch:
diff --git a/tests/cupy_tests/core_tests/fusion_tests/test_function.py b/tests/cupy_tests/core_tests/fusion_tests/test_function.py
--- a/tests/cupy_tests/core_tests/fusion_tests/test_function.py
+++ b/tests/cupy_tests/core_tests/fusion_tests/test_function.py
@@ -1,7 +1,6 @@
 import threading
 import unittest
-
-import mock
+from unittest import mock
 
 import cupy
 from cupy import testing
@@ -200,7 +199,7 @@ def check(self, xp, func, expected_name, is_elementwise):
 
             with mock.patch(target_full_name) as kernel:
                 func(a, b, c)
-                kernel.assert_called_once()
+                assert kernel.call_count == 1
                 self.assertEqual(kernel.call_args[1]['name'], expected_name)
 
         # Test there's no error in computation (without mock)
diff --git a/tests/cupy_tests/cuda_tests/test_compiler.py b/tests/cupy_tests/cuda_tests/test_compiler.py
--- a/tests/cupy_tests/cuda_tests/test_compiler.py
+++ b/tests/cupy_tests/cuda_tests/test_compiler.py
@@ -1,7 +1,6 @@
 import pickle
 import unittest
-
-import mock
+from unittest import mock
 
 import cupy
 from cupy.cuda import compiler
diff --git a/tests/cupy_tests/cuda_tests/test_profile.py b/tests/cupy_tests/cuda_tests/test_profile.py
--- a/tests/cupy_tests/cuda_tests/test_profile.py
+++ b/tests/cupy_tests/cuda_tests/test_profile.py
@@ -1,6 +1,5 @@
 import unittest
-
-import mock
+from unittest import mock
 
 from cupy import cuda
 
diff --git a/tests/cupy_tests/prof_tests/test_range.py b/tests/cupy_tests/prof_tests/test_range.py
--- a/tests/cupy_tests/prof_tests/test_range.py
+++ b/tests/cupy_tests/prof_tests/test_range.py
@@ -1,6 +1,5 @@
 import unittest
-
-import mock
+from unittest import mock
 
 from cupy import cuda
 from cupy import prof
diff --git a/tests/cupy_tests/random_tests/test_sample.py b/tests/cupy_tests/random_tests/test_sample.py
--- a/tests/cupy_tests/random_tests/test_sample.py
+++ b/tests/cupy_tests/random_tests/test_sample.py
@@ -1,5 +1,5 @@
-import mock
 import unittest
+from unittest import mock
 
 import numpy
 
diff --git a/tests/cupy_tests/test_init.py b/tests/cupy_tests/test_init.py
--- a/tests/cupy_tests/test_init.py
+++ b/tests/cupy_tests/test_init.py
@@ -4,8 +4,8 @@
 import sys
 import tempfile
 import unittest
+from unittest import mock
 
-import mock
 import numpy
 
 import cupy
diff --git a/tests/cupyx_tests/scipy_tests/sparse_tests/test_construct.py b/tests/cupyx_tests/scipy_tests/sparse_tests/test_construct.py
--- a/tests/cupyx_tests/scipy_tests/sparse_tests/test_construct.py
+++ b/tests/cupyx_tests/scipy_tests/sparse_tests/test_construct.py
@@ -1,7 +1,7 @@
 import re
 import unittest
+from unittest import mock
 
-import mock
 import numpy
 import pytest
 try:
diff --git a/tests/cupyx_tests/test_optimize.py b/tests/cupyx_tests/test_optimize.py
--- a/tests/cupyx_tests/test_optimize.py
+++ b/tests/cupyx_tests/test_optimize.py
@@ -1,7 +1,8 @@
-import mock
-import pytest
 import tempfile
 import unittest
+from unittest import mock
+
+import pytest
 
 import cupy
 from cupy import testing
diff --git a/tests/cupyx_tests/test_runtime.py b/tests/cupyx_tests/test_runtime.py
--- a/tests/cupyx_tests/test_runtime.py
+++ b/tests/cupyx_tests/test_runtime.py
@@ -1,6 +1,5 @@
 import unittest
-
-import mock
+from unittest import mock
 
 import cupy
 import cupyx
diff --git a/tests/cupyx_tests/test_time.py b/tests/cupyx_tests/test_time.py
--- a/tests/cupyx_tests/test_time.py
+++ b/tests/cupyx_tests/test_time.py
@@ -1,5 +1,5 @@
-import mock
 import unittest
+from unittest import mock
 
 import numpy