Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange warning potentially related with the way pytest imports modules in conftest.py. #9072

Open
okhoma opened this issue Sep 3, 2021 · 3 comments
Labels
plugin: warnings related to the warnings builtin plugin topic: config related to config handling, argument parsing and config file

Comments

@okhoma
Copy link

okhoma commented Sep 3, 2021

  1. Create new environment:
conda create -p .\env_minimal python pytest numpy netCDF4
  1. Create test_netcdf4.py with a single line of code:
import netCDF4
  1. Create conftest.py with a single line of code:
import numpy
  1. Run pytest:
pytest test_netcdf4.py
  1. Warning is displayed:
========================================== test session starts ==========================================
platform win32 -- Python 3.9.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: E:\LDC-RR-Jenkins-Docker
collected 0 items                                                                                        

=========================================== warnings summary ============================================
<frozen importlib._bootstrap>:228
  <frozen importlib._bootstrap>:228: RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility. Expected 16 from C header, got 88 from PyObject

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================================== 1 warning in 1.28s ===========================================
  1. Moving both import statements into either test_netcdf4.py or conftest.py or removing import numpy from conftest.py no longer produces warning
========================================== test session starts ==========================================
platform win32 -- Python 3.9.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: E:\LDC-RR-Jenkins-Docker
collected 0 items                                                                                        

========================================= no tests ran in 0.46s =========================================

--
conda list output:

# Name                    Version                   Build  Channel
atomicwrites              1.4.0                      py_0
attrs                     21.2.0             pyhd3eb1b0_0
blas                      1.0                         mkl
ca-certificates           2021.7.5             haa95532_1
certifi                   2021.5.30        py39haa95532_0
cftime                    1.5.0            py39h080aedc_0
colorama                  0.4.4              pyhd3eb1b0_0
curl                      7.78.0               h86230a5_0
hdf4                      4.2.13               h712560f_2
hdf5                      1.10.6               h7ebc959_0
icc_rt                    2019.0.0             h0cc432a_1
iniconfig                 1.1.1              pyhd3eb1b0_0
intel-openmp              2021.3.0          haa95532_3372
jpeg                      9b                   hb83a4c4_2
krb5                      1.19.2               h5b6d351_0
libcurl                   7.78.0               h86230a5_0
libnetcdf                 4.6.1                hf59b723_4
libssh2                   1.9.0                h7a1dbc1_1
mkl                       2021.3.0           haa95532_524
mkl-service               2.4.0            py39h2bbff1b_0
mkl_fft                   1.3.0            py39h277e83a_2
mkl_random                1.2.2            py39hf11a4ad_0
more-itertools            8.8.0              pyhd3eb1b0_0
netcdf4                   1.5.7            py39hb76ebac_0
numpy                     1.20.3           py39ha4e8547_0
numpy-base                1.20.3           py39hc2deb75_0
openssl                   1.1.1l               h2bbff1b_0
packaging                 21.0               pyhd3eb1b0_0
pip                       21.2.4           py38haa95532_0
pluggy                    0.13.1           py39haa95532_0
py                        1.10.0             pyhd3eb1b0_0
pyparsing                 2.4.7              pyhd3eb1b0_0
pytest                    6.2.4            py39haa95532_2
python                    3.9.6                h6244533_1
setuptools                52.0.0           py39haa95532_0
six                       1.16.0             pyhd3eb1b0_0
sqlite                    3.36.0               h2bbff1b_0
toml                      0.10.2             pyhd3eb1b0_0
tzdata                    2021a                h5d7bf9c_0
vc                        14.2                 h21ff451_1
vs2015_runtime            14.27.29016          h5e58377_2
wheel                     0.37.0             pyhd3eb1b0_0
wincertstore              0.2              py39h2bbff1b_0
zlib                      1.2.11               h62dcd97_4

Reproduced on Windows and on Mac OS X.

@nicoddemus
Copy link
Member

Hi,

I'm not sure it is related to how pytest imports things, but the order things are imported (say numpy first then netCDF4, or vice versa).

This can be tested by creating two files:

# file num.py
import numpy
import netCDF4
# file net.py
import netCFD4
import numpy

And then executing python -W always num.py and python -W always net.py to see if either of them produces the same warning. Can you give that a try? Thanks!

@nicoddemus nicoddemus added the status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity label Sep 3, 2021
@okhoma
Copy link
Author

okhoma commented Sep 4, 2021

Hi! Thanks for looking into this, but there are no warnings in both cases that you have proposed.

@nicoddemus
Copy link
Member

Thanks for checking it out.

Hmmm seems like pytest's own imports are causing that warning then, for some reason...

@nicoddemus nicoddemus added plugin: warnings related to the warnings builtin plugin topic: config related to config handling, argument parsing and config file and removed status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity labels Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: warnings related to the warnings builtin plugin topic: config related to config handling, argument parsing and config file
Projects
None yet
Development

No branches or pull requests

2 participants