Repository: cupy/cupy

Issue:
cupy + pytest seem to leave orphaned files
### Description

i know this is likely a conda(-forge) issue but I figured maybe i could help help from all of you as well since the maintainers likely overlap.

Basically, running pytest + cupy seems to generate some pyc files, but for only one of the python files that seems somewhat innocent.

It seems like a special behavior that somebody might remember.


### To Reproduce

See https://github.com/conda-forge/cupy-feedstock/issues/188#issuecomment-1449217000

### Installation

Conda-Forge (`conda install ...`)

### Environment

See details https://github.com/conda-forge/cupy-feedstock/issues/188#issuecomment-1449217000

### Additional Information

pytest?
```
# packages in environment at /home/mark/mambaforge/envs/cupy:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
attrs                     22.2.0             pyh71513ae_0    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
ca-certificates           2022.12.7            ha878542_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
cudatoolkit               11.8.0              h37601d7_11    conda-forge
cupy                      11.5.0          py311hb8138a5_0    conda-forge
exceptiongroup            1.1.0              pyhd8ed1ab_0    conda-forge
fastrlock                 0.8.1                    pypi_0    pypi
iniconfig                 2.0.0              pyhd8ed1ab_0    conda-forge
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
libblas                   3.9.0           16_linux64_openblas    conda-forge
libcblas                  3.9.0           16_linux64_openblas    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 12.2.0              h65d4601_19    conda-forge
libgfortran-ng            12.2.0              h69a702a_19    conda-forge
libgfortran5              12.2.0              h337968e_19    conda-forge
libgomp                   12.2.0              h65d4601_19    conda-forge
liblapack                 3.9.0           16_linux64_openblas    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libopenblas               0.3.21          pthreads_h78a6416_3    conda-forge
libsqlite                 3.40.0               h753d276_0    conda-forge
libstdcxx-ng              12.2.0              h46fd767_19    conda-forge
libuuid                   2.32.1            h7f98852_1000    conda-forge
libzlib                   1.2.13               h166bdaf_4    conda-forge
ncurses                   6.3                  h27087fc_1    conda-forge
numpy                     1.24.2          py311h8e6699e_0    conda-forge
openssl                   3.0.8                h0b41bf4_0    conda-forge
packaging                 23.0               pyhd8ed1ab_0    conda-forge
pip                       23.0.1             pyhd8ed1ab_0    conda-forge
pluggy                    1.0.0              pyhd8ed1ab_5    conda-forge
pytest                    7.2.1              pyhd8ed1ab_0    conda-forge
python                    3.11.0          he550d4f_1_cpython    conda-forge
python_abi                3.11                    3_cp311    conda-forge
readline                  8.1.2                h0f457ee_0    conda-forge
setuptools                67.4.0             pyhd8ed1ab_0    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
tzdata                    2022g                h191b570_0    conda-forge
wheel                     0.38.4             pyhd8ed1ab_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
```


Discussion:
A symptom that this creates for end users is that:

1. They install dask + cupy + pytest
2. They run pytest
3. They uninstall cupy
4. Now dask array won't even import.
xref: https://github.com/conda-forge/cupy-feedstock/issues/188#issuecomment-1449274577
xref: https://github.com/pytest-dev/pytest/issues/10781

I believe this is a thing that needs to be fixed in pytest (as the glob pattern for test code may be vary depending on `python_files` configuration), but if you need an immediate fix I'm happy to rename `type_test.py` to `type_testing.py` :)

SciPy also seems to be affected. `site-packages/scipy/stats/__pycache__/_page_trend_test.cpython-39-pytest-5.4.2.pyc` is generated for `scipy/stats/_page_trend_test.py` in my environment.

the reason why i probably didn't see it happen in scipy is that "scipy" is hardware agnostic so in our workflows we typically do not uninstall it. 

For cupy so we typically go through many install, pytest, uninstall, pytest cycles on our development environments so this appeared quite quickly.

An immediate fix would be welcome. 

(I do think that packages like `pytest` should be more conscious in leaving files in the site-packages directory. it is often not even writable.)

Resolving patch:
diff --git a/cupy/__init__.py b/cupy/__init__.py
--- a/cupy/__init__.py
+++ b/cupy/__init__.py
@@ -493,11 +493,11 @@ def base_repr(number, base=2, padding=0):  # NOQA (needed to avoid redefinition
 from cupy._logic.truth import in1d  # NOQA
 from cupy._logic.truth import isin  # NOQA
 
-from cupy._logic.type_test import iscomplex  # NOQA
-from cupy._logic.type_test import iscomplexobj  # NOQA
-from cupy._logic.type_test import isfortran  # NOQA
-from cupy._logic.type_test import isreal  # NOQA
-from cupy._logic.type_test import isrealobj  # NOQA
+from cupy._logic.type_testing import iscomplex  # NOQA
+from cupy._logic.type_testing import iscomplexobj  # NOQA
+from cupy._logic.type_testing import isfortran  # NOQA
+from cupy._logic.type_testing import isreal  # NOQA
+from cupy._logic.type_testing import isrealobj  # NOQA
 
 from cupy._logic.truth import in1d  # NOQA
 from cupy._logic.truth import intersect1d  # NOQA


Test patch:
diff --git a/cupy/_logic/type_test.py b/cupy/_logic/type_testing.py
similarity index 100%
rename from cupy/_logic/type_test.py
rename to cupy/_logic/type_testing.py