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

DeprecationWarning when used with pytest #466

Closed
cubranic opened this issue Jan 22, 2019 · 11 comments
Closed

DeprecationWarning when used with pytest #466

cubranic opened this issue Jan 22, 2019 · 11 comments

Comments

@cubranic
Copy link

Describe the bug
Using pyfakefs with pytest produces a deprecation warning about the compiler package as soon as a test depends on the fs fixture.

plugins: pyfakefs-3.5.6
collected 1 item

tests/test_foo.py .                                                                                           [100%]

================================================= warnings summary ==================================================
tests/test_foo.py::test_fs
  /usr/local/miniconda3/envs/alpenhorn/lib/python2.7/site-packages/py/_code/_assertionold.py:3: DeprecationWarning: The compiler package is deprecated and removed in Python 3.x.
    from compiler import parse, ast, pycodegen

-- Docs: https://docs.pytest.org/en/latest/warnings.html
======================================= 1 passed, 1 warnings in 0.11 seconds ========================================

How To Reproduce
Put the following into test_foo.py:

def test_foo(fs):
    pass

Then run pytest test_foo.py.

Your enviroment
Please run the following and paste the output.

Darwin-18.0.0-x86_64-i386-64bit
('Python', '2.7.15 |Anaconda, Inc.| (default, Dec 14 2018, 13:10:39) \n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]')
('pyfakefs', '3.5.6')
@mrbean-bremen
Copy link
Member

There is an old (and long fixed) pytest bug, which may be related - can you please check which version of pytest you use?

@cubranic
Copy link
Author

Showing DeprecationWarnings from system libraries has been enabled in Pytest 3.8. I'm running Pytest 4.1.1, the latest version on Conda.

@cubranic
Copy link
Author

I was able to silence the warning with a filter in the configuration file, as described on the same Pytest page. But if pytest is directly importing the compiler package, perhaps the import statement can be wrapped in some kind of logging filter?

@mrbean-bremen
Copy link
Member

Ah, ok - I had used an older version of pytest, now I see the warning, too, thanks!
It is strange that this warning is still occurring (pytest is imported a lot if used in tests), but wrapping the import in a logging filter sounds like a good idea.

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Jan 22, 2019

Hm, I didn't succeed in filtering out the warning so far (other than in the config file or on the command line) - maybe I'm doing something wrong. I will check again another day.

@mrbean-bremen
Copy link
Member

I had another try, and couldn't get it to work - either I'm doing something wrong, or this has to be fixed in pytest itself. I'm out of ideas right now. @jmcgeheeiv - any thoughts?

@diefans
Copy link

diefans commented Mar 21, 2019

@mrbean-bremen

[pytest]
filterwarnings =
    ignore::DeprecationWarning 
# pyfakefs/fake_filesystem_unittest.py
# line 482
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                modules = {name: mod for name, mod in module.__dict__.items()
                           if is_fs_module(mod, name)}

@mrbean-bremen
Copy link
Member

@diefans - thanks! I will have a look at this sometime next week, I'm traveling right now.

@jmcgeheeiv
Copy link
Contributor

I'm sorry, but I do not see what the problem could be.

@diefans
Copy link

diefans commented Mar 25, 2019

When I put catch_warnings context around modules = ... I do not get deprecation warnings in python 2.7...

@mrbean-bremen
Copy link
Member

@diefans - thanks for that - this works nicely! I obviously had put the filter into the wrong place.
And we can make this very specific to suppress only this one warning...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants