pytest-dev / pytest-dev/pytest

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

Open
#9,072 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: warnings topic: config
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

  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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Recreate the minimal conda environment with test_netcdf4.py and conftest.py, then run pytest test_netcdf4.py with the imports split and combined. Compare the Windows and macOS results and inspect pytest's handling of the conftest.py import. Done means identifying whether pytest causes the warning and establishing a regression test or a clear explanation of the external cause.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.