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

unable to import within test function when using fs fixture and python 2.7 #472

Closed
diefans opened this issue Mar 13, 2019 · 3 comments
Closed

Comments

@diefans
Copy link

diefans commented Mar 13, 2019

Describe the bug

$ pipenv run pytest
========================================== test session starts ==========================================
platform linux2 -- Python 2.7.15, pytest-4.3.1, py-1.8.0, pluggy-0.9.0
rootdir: /home/olli/code/da/pyfakefs-bug, inifile:
plugins: pyfakefs-3.5.7
collected 1 item

test_foo.py F                                                                                     [100%]

=============================================== FAILURES ================================================
______________________________________________ test_import ______________________________________________

fs = <pyfakefs.fake_filesystem.FakeFilesystem object at 0x7fe551c9f310>

    def test_import(fs):
>       import foo

/home/olli/code/da/pyfakefs-bug/test_foo.py:2:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/olli/code/da/pyfakefs-bug/foo.py:1: in <module>
    ???
/home/olli/.local/share/virtualenvs/pyfakefs-bug-qrOR-hXJ/lib/python2.7/site-packages/gevent/__init__.py:86: in <module>
    ???
/home/olli/.local/share/virtualenvs/pyfakefs-bug-qrOR-hXJ/lib/python2.7/site-packages/gevent/_config.py:699: in <module>
    ???
/home/olli/.local/share/virtualenvs/pyfakefs-bug-qrOR-hXJ/lib/python2.7/site-packages/gevent/_config.py:146: in get
    ???
/home/olli/.local/share/virtualenvs/pyfakefs-bug-qrOR-hXJ/lib/python2.7/site-packages/gevent/_config.py:248: in validate
    ???
/home/olli/.local/share/virtualenvs/pyfakefs-bug-qrOR-hXJ/lib/python2.7/site-packages/gevent/_config.py:219: in _import_one_of
    ???
/home/olli/.local/share/virtualenvs/pyfakefs-bug-qrOR-hXJ/lib/python2.7/site-packages/gevent/_config.py:237: in _import_one
    ???
/home/olli/.pyenv/versions/2.7.15/lib/python2.7/importlib/__init__.py:37: in import_module
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   ???
E   NameError: name '__import__' is not defined

src/gevent/libev/corecext.pyx:1: NameError
=========================================== warnings summary ============================================
test_foo.py::test_import
  /home/olli/.local/share/virtualenvs/pyfakefs-bug-qrOR-hXJ/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 failed, 1 warnings in 0.19 seconds ==================================

This happens only in python 2.7.

How To Reproduce

(
DIR=$(mktemp -d)
cd ${DIR}
pipenv --python 2.7
pipenv install pytest pyfakefs gevent

cat > foo.py << EOF
import gevent
EOF

cat > test_foo.py << EOF
def test_import(fs):
    import foo
EOF

pipenv run pytest
rm -r ${DIR}
)

Your enviroment

$ pipenv run python -c "import platform; print(platform.platform())"
Linux-4.20.10-zen1-1-zen-x86_64-with-glibc2.7
$ pipenv run python -c "import sys; print('Python', sys.version)"
('Python', '2.7.15 (default, Oct  1 2018, 22:14:38) \n[GCC 5.5.0 20171010]')
$ pipenv run python -c "from pyfakefs.fake_filesystem import __version__; print('pyfakefs', __version__)"
('pyfakefs', '3.5.7')
@mrbean-bremen
Copy link
Member

This could be a duplicate of #469. Can you please check if this also happens with current master?

@diefans
Copy link
Author

diefans commented Mar 13, 2019

indeed actual master fixes the issue for me.

@diefans diefans closed this as completed Mar 13, 2019
@mrbean-bremen
Copy link
Member

Ok, I was planning to make a new minor release anyway - I may do it later today, before this turns up again.

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

2 participants