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

Tests fail when trying relative conftest import #14

Open
offlinehacker opened this issue Sep 20, 2013 · 10 comments
Open

Tests fail when trying relative conftest import #14

offlinehacker opened this issue Sep 20, 2013 · 10 comments

Comments

@offlinehacker
Copy link

tests/stores/conftest.py:7: in

from ..conftest import Base
E ValueError: Attempted relative import beyond toplevel package

I'm using pytest 2.3.5

How can i solve this? thanks!

@dahlia
Copy link
Owner

dahlia commented Sep 20, 2013

How did you run tests? We recommend you to use tox e.g.:

$ tox  # tests run on py26,py27,py32,py33, and pypy
$ tox -e py27,py33  # tests run on only py27 and py33
$ tox -- -k store  # `-k store` option is forwarded to py.test

@offlinehacker
Copy link
Author

I'm making a package for linux distribution, more precisely nixos (it is
standard that if we can test a package, package is tested after build
phase). I tried both the standard setuptools "python setup.py test" and
"py.test", and both failed with same error. I'm testing only for a singe
python version, because we have different packages per python versions.

On Fri, Sep 20, 2013 at 4:13 PM, Hong Minhee [email protected]:

How did you run tests? We recommend you to use toxhttp://testrun.org/tox/e.g.:

$ tox # tests run on py26,py27,py32,py33, and pypy$ tox -e py27,py33 # tests run on only py27 and py33$ tox -- -k store # -k store option is forwarded to py.test


Reply to this email directly or view it on GitHubhttps://github.com//issues/14#issuecomment-24813054
.

@dahlia
Copy link
Owner

dahlia commented Sep 20, 2013

Invoking py.test (without any arguments) must simply work. Did you happen to run tests in tests/ directory? It should be run at root of the source tree.

@offlinehacker
Copy link
Author

I run it from root of the tree and i get this error. How could i debug this
any further?

On Fri, Sep 20, 2013 at 8:19 PM, Hong Minhee [email protected]:

Invoking py.test (without any arguments) must simply work. Did you happen
to run tests in tests/ directory? It should be run at root of the source
tree.


Reply to this email directly or view it on GitHubhttps://github.com//issues/14#issuecomment-24830368
.

@offlinehacker
Copy link
Author

And yes, i'm using python 2.7

On Fri, Sep 20, 2013 at 11:41 PM, Jaka Hudoklin [email protected]:

I run it from root of the tree and i get this error. How could i debug
this any further?

On Fri, Sep 20, 2013 at 8:19 PM, Hong Minhee [email protected]:

Invoking py.test (without any arguments) must simply work. Did you
happen to run tests in tests/ directory? It should be run at root of the
source tree.


Reply to this email directly or view it on GitHubhttps://github.com//issues/14#issuecomment-24830368
.

@dahlia
Copy link
Owner

dahlia commented Sep 21, 2013

I just noticed that the error type is not ImportError but ValueError. Can I see the more detailed trackback? Try -vv option.

@offlinehacker
Copy link
Author

Okay here is the whole backtrace:

============================= test session starts ==============================
platform linux2 -- Python 2.7.5 -- pytest-2.3.5 -- /nix/store/1i5rd0mp4x57gzjii9z2pg3mjgzj95q6-python-2.7.5/bin/python2.7
collecting ... collected 0 items / 1 errors

==================================== ERRORS ====================================
______________________________ ERROR collecting . ______________________________
/nix/store/r845pd45751jzbi1fg8dng571hpfpmh6-python2.7-py-1.4.13/lib/python2.7/site-packages/py-1.4.13-py2.7.egg/py/_path/common.py:315: in visit
>       for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
/nix/store/r845pd45751jzbi1fg8dng571hpfpmh6-python2.7-py-1.4.13/lib/python2.7/site-packages/py-1.4.13-py2.7.egg/py/_path/common.py:361: in gen
>               for p in self.gen(subdir):
/nix/store/r845pd45751jzbi1fg8dng571hpfpmh6-python2.7-py-1.4.13/lib/python2.7/site-packages/py-1.4.13-py2.7.egg/py/_path/common.py:351: in gen
>                   if p.check(dir=1) and (rec is None or rec(p))])
/nix/store/f5g5l96afv66zqr34n3krswc7wzq1mf0-python2.7-pytest-2.3.5/lib/python2.7/site-packages/pytest-2.3.5-py2.7.egg/_pytest/main.py:548: in _recurse
>       ihook.pytest_collect_directory(path=path, parent=self)
/nix/store/f5g5l96afv66zqr34n3krswc7wzq1mf0-python2.7-pytest-2.3.5/lib/python2.7/site-packages/pytest-2.3.5-py2.7.egg/_pytest/main.py:158: in call_matching_hooks
>       plugins = self.config._getmatchingplugins(self.fspath)
/nix/store/f5g5l96afv66zqr34n3krswc7wzq1mf0-python2.7-pytest-2.3.5/lib/python2.7/site-packages/pytest-2.3.5-py2.7.egg/_pytest/config.py:319: in _getmatchingplugins
>       plugins += self._conftest.getconftestmodules(fspath)
/nix/store/f5g5l96afv66zqr34n3krswc7wzq1mf0-python2.7-pytest-2.3.5/lib/python2.7/site-packages/pytest-2.3.5-py2.7.egg/_pytest/config.py:214: in getconftestmodules
>                       clist.append(self.importconftest(conftestpath))
/nix/store/f5g5l96afv66zqr34n3krswc7wzq1mf0-python2.7-pytest-2.3.5/lib/python2.7/site-packages/pytest-2.3.5-py2.7.egg/_pytest/config.py:243: in importconftest
>           self._conftestpath2mod[conftestpath] = mod = conftestpath.pyimport()
/nix/store/r845pd45751jzbi1fg8dng571hpfpmh6-python2.7-py-1.4.13/lib/python2.7/site-packages/py-1.4.13-py2.7.egg/py/_path/local.py:548: in pyimport
>           __import__(modname)
tests/stores/conftest.py:7: in <module>
>   from ..conftest import Base
E   ValueError: Attempted relative import beyond toplevel package

Sorry for wierd paths, but that is how nix package manager works (stores everything under /nix/store/hash+package_name).

@dahlia
Copy link
Owner

dahlia commented Sep 21, 2013

Could you paste the output of tree command from root of the source tree as well?

@offlinehacker
Copy link
Author

Okay i think i now see the problem too, looks like not all files are included in pypi archive. For now i will just switch to git as a source, but it would be nice to include missing files.

Here is output of tree, right after failed tests. Sorry for those ugly chars, terminal copy makes problems.

.
��� build
�   ��� bdist.linux-x86_64
�   ��� lib
�       ��� sqlalchemy_imageattach
�           ��� context.py
�           ��� entity.py
�           ��� file.py
�           ��� __init__.py
�           ��� migration.py
�           ��� store.py
�           ��� stores
�           �   ��� fs.py
�           �   ��� __init__.py
�           �   ��� s3.py
�           ��� util.py
�           ��� version.py
��� PKG-INFO
��� README.rst
��� setup.cfg
��� setup.py
��� sqlalchemy_imageattach
�   ��� context.py
�   ��� entity.py
�   ��� file.py
�   ��� __init__.py
�   ��� __init__.pyc
�   ��� migration.py
�   ��� store.py
�   ��� stores
�   �   ��� fs.py
�   �   ��� __init__.py
�   �   ��� s3.py
�   ��� util.py
�   ��� version.py
�   ��� version.pyc
��� SQLAlchemy_ImageAttach.egg-info
�   ��� dependency_links.txt
�   ��� PKG-INFO
�   ��� requires.txt
�   ��� SOURCES.txt
�   ��� top_level.txt
��� temp
��� tests
    ��� stores
        ��� conftest.py
        ��� conftest.pyc
        ��� fs_test.py
        ��� __init__.py
        ��� __init__.pyc
        ��� s3_test.py

@dahlia
Copy link
Owner

dahlia commented Sep 21, 2013

That’s indeed problematic, so I will include these missing files as well. Thanks!

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

No branches or pull requests

2 participants