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

Pytest fails on importing package in conftest.py with --cache-clear option #8543

Closed
martinwk opened this issue Apr 12, 2021 · 5 comments
Closed
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity

Comments

@martinwk
Copy link

martinwk commented Apr 12, 2021

The bug regards the import of the python package fipy I have installed with conda. If I import the package in the test_.py file, everything runs fine. If I import it in the conftest.py it also works fine. BUT when I add the --cache-clear option test discovery fails.
So this command works: python -m pytest --rootdir "c:\Users\korevma\Repositories\wt_process_models" -s tests_1 although it throws the following warning

============================================================================================================================================= test session starts ==============================================================================================================================================
platform win32 -- Python 3.6.13, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- C:\Users\korevma\AppData\Local\Continuum\miniconda3\envs\wt_process_models\python.exe
cachedir: .pytest_cache
rootdir: c:\Users\korevma\Repositories\wt_process_models, configfile: pytest.ini
collected 1 item                                                                                                                                                                                                                                                                                                

tests_1/test_something.py::test_this PASSED

=============================================================================================================================================== warnings summary ===============================================================================================================================================
..\..\AppData\Local\Continuum\miniconda3\envs\wt_process_models\lib\site-packages\future\standard_library\__init__.py:65
  C:\Users\korevma\AppData\Local\Continuum\miniconda3\envs\wt_process_models\lib\site-packages\future\standard_library\__init__.py:65: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================================================================================================================================= 1 passed, 1 warning in 1.27s =========================================================================================================================================

while adding the --cache-clear option fails

$ python -m pytest --rootdir "c:\Users\korevma\Repositories\wt_process_models" -s --cache-clear tests_1
Usage: __main__.py [options]

__main__.py: error: no such option: --cache-clear

If I remove the line import fipy from conftest.py python -m pytest --rootdir "c:\Users\korevma\Repositories\wt_process_models" -s --cache-clear tests_1 passes without errors or warnings

conftest.py

import fipy
import pytest


@pytest.fixture
def some_fixture():
    return 123

test_something.py

import pytest
# from wt_process_models import base_classes as bc

def test_this():
    assert True

pytest.ini

[pytest]
testpaths = tests
addopts =
    -r a
    -v
junit_family=legacy

packages and OS versions

platform win32 -- Python 3.6.13, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- C:\Users\korevma\AppData\Local\Continuum\miniconda3\envs\wt_process_models\python.exe

pip -list

Package                       Version
----------------------------- ------------
alabaster                     0.7.12
apptools                      5.1.0
APScheduler                   3.7.0
astroid                       2.4.2
atomicwrites                  1.4.0
attrs                         20.3.0
autopep8                      1.5.5
Babel                         2.9.0
backports.functools-lru-cache 1.6.3
brotlipy                      0.7.0
certifi                       2020.12.5
cffi                          1.14.5
chardet                       4.0.0
colorama                      0.4.4
configobj                     5.0.6
cryptography                  3.4.7
cycler                        0.10.0
decorator                     5.0.5
docutils                      0.17
envisage                      4.9.2
et-xmlfile                    1.0.1
FiPy                          3.4.2.1
future                        0.18.2
idna                          2.10
imagesize                     1.2.0
importlib-metadata            3.10.0
importlib-resources           5.1.2
iniconfig                     1.1.1
ipdb                          0.13.4
ipython                       5.8.0
ipython-genutils              0.2.0
isort                         5.8.0
jdcal                         1.4.1
Jinja2                        2.11.3
joblib                        1.0.1
kiwisolver                    1.3.1
lazy-object-proxy             1.4.3
MarkupSafe                    1.1.1
matplotlib                    3.3.4
mayavi                        4.7.1
mccabe                        0.6.1
more-itertools                8.7.0
numpy                         1.19.5
olefile                       0.46
openpyxl                      3.0.6
packaging                     20.9
pandas                        1.1.5
patsy                         0.5.1
pickleshare                   0.7.5
Pillow                        8.1.2
Pint                          0.16.1
pip                           21.0.1
plotly                        4.14.3
pluggy                        0.13.1
prompt-toolkit                1.0.15
py                            1.10.0
pycodestyle                   2.7.0
pycparser                     2.20
pyface                        7.3.0
Pygments                      2.8.1
pyiast                        1.4.3
pylint                        2.6.0
pyOpenSSL                     20.0.1
pyparsing                     2.4.7
PyQt5                         5.12.3
PyQt5-sip                     4.19.18
PyQtChart                     5.12
PyQtWebEngine                 5.12.1
PySocks                       1.7.1
pytest                        6.2.2
python-dateutil               2.8.1
pytz                          2021.1
requests                      2.25.1
retrying                      1.3.3
scikit-learn                  0.23.1
scipy                         1.5.3
seaborn                       0.11.1
setuptools                    46.1.3
simplegeneric                 0.8.1
six                           1.15.0
snowballstemmer               2.1.0
Sphinx                        3.5.3
sphinx-rtd-theme              0.5.1
sphinxcontrib-applehelp       1.0.2
sphinxcontrib-devhelp         1.0.2
sphinxcontrib-htmlhelp        1.0.3
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.3
sphinxcontrib-serializinghtml 1.1.4
statsmodels                   0.12.2
threadpoolctl                 2.1.0
toml                          0.10.2
tornado                       6.1
traitlets                     4.3.3
traits                        6.2.0
traitsui                      7.1.0
typed-ast                     1.4.2
typing-extensions             3.7.4.3
tzlocal                       2.0.0
urllib3                       1.26.4
vtk                           -PKG-VERSION
wcwidth                       0.2.5
wheel                         0.34.2
win-inet-pton                 1.1.0
wincertstore                  0.2
wrapt                         1.11.2
zipp                          3.4.1
@The-Compiler
Copy link
Member

Are you really running python -m pytest in the first example? What you see in the second example isn't actually pytest, it's a thing called "pytest" (but totally unrelated to this project) coming from old pylint versions, via logilab-common: #1833 - I suspect you're running things in two different environments.

@The-Compiler The-Compiler added the status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity label Apr 12, 2021
@asottile
Copy link
Member

the warning there comes from some chain of things importing future (which imports the deprecated imp module) -- this is unrelated to pytest

@martinwk
Copy link
Author

So this is something that needs to be addressed by the package I rely on, of which I can't do much about it. So best solution is to catch and silent that warning I presume?

@asottile
Copy link
Member

yep! here's the docs on that: https://docs.pytest.org/en/stable/warnings.html

though realistically, the dependency should probably be fixed to not need python-future since python2 support is probably not desirable

@martinwk
Copy link
Author

Thanks for the link!

I agree that it should this should be solved in the dependency itself, but there is much I can do. There is only so much we can do in a day🙂 I will file a feature request there as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants