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

chdir away from tox.ini directory during test #54

Closed
pytoxbot opened this issue Sep 17, 2016 · 11 comments
Closed

chdir away from tox.ini directory during test #54

pytoxbot opened this issue Sep 17, 2016 · 11 comments

Comments

@pytoxbot
Copy link

tox seems to run code with the directory containing tox.ini in the PYTHONPATH, loading code from the checkout instead of the installed sdist inside the virtualenv. Instead, tox should chdir to catch 'forgot to include something in sdist' errors.

@pytoxbot
Copy link
Author

Original comment by @brechtm

In general, it's a good idea to place your packages in an src directory. This also prevents the packages in your toxinidir from shadowing an installed copy.

Read these for why you should use an src directory:

@pytoxbot
Copy link
Author

Original comment by @brechtm

To change to an empty directory before running tests, one can set changedir to {envtmpdir}. Use {toxinidir} to locate your files. Here's an example: tox.ini.

@pytoxbot
Copy link
Author

Original comment by @brechtm

As I understand it, Python always first searches the working directory when importing a package or module. The working directory (where tox.ini lives) is typically a repository checkout. Often the package source code is stored in a directory that matches the package name. In that case, this directory will shadow the installed package, and tox is in fact not testing the installed package.

This is a critical problem for packages that modify (2to3) source files on installation.

Wouldn't it be best that the working directory is always a temporary, empty directory to make sure there's nothing strange going on?

@pytoxbot
Copy link
Author

Original comment by @bittner

As mentioned in a comment on issues 13 and 185 I'd love to see the tox configuration live in setup.cfg, as an alternative at least.

Just making sure to reach some interested audience.

@pytoxbot
Copy link
Author

Original comment by @hpk42

right, the idea of "testlocations" would be to do copying of them to some environment directory in order to perform 2to3 or other transforms.

In general, i'd like tox to learn to generate setup.py/setup.cfg for a project (so everything could be based on tox.ini using PEP426 compliant metadata). If that happens we could think about also generating test packages and installing them, based on the same metadata.

@pytoxbot
Copy link
Author

Original comment by @jenisys

The "test" directory (not: "tests") contains an empty "init.py" file.

A feature like "testlocations = ..." would be good idea. Testing is the primary use case.
But I think the problem is more general; something like one or more copytree commands are needed (at least for me).

@pytoxbot
Copy link
Author

Original comment by @hpk42

@Jenisis does you "tests" directory contain an init.py by chance? This would lead pytest to insert the parent dir of "tests" and if you packages lives at the same level this can lead to importing the non-installed package. Clearly, this is too unpredictable. I think tox should grow an "testlocations = ..." or similar option which allow to specify where the test directoryies/file live (with glob patterns etc.). If that option is specified, they would be copied to the environment and there could be an optional "2to3" step before running tests there.

@pytoxbot
Copy link
Author

Original comment by @jenisys

I just ran into the same issue. The project is using nose as test runner. Therefore, I cannot switch. As an experiment I replaced nosetests with py.test and I cannot confirm that py.test is using the installed package in the virtual environment. It is using the local package according to the stack traces of the failed tests (sorry: Ronny). I assume the behavior depends how the PATH environment variable is set.


One changedir command can be applied by using the testenv:changdir option in the tox.ini configuration file:

#!ini
# FILE: tox.ini
...
[testenv]
changedir = {toxworkdir}/{envname}
commands =
     py.test {toxinidir}/tests

The default value for changeddir is {toxinidir} which causes the problems described above. Maybe the default value should be changed ?!? or a documentation hint should be provided (or the people should learn to read the documentation, including myself).

@pytoxbot
Copy link
Author

Original comment by @RonnyPfannschmidt

also there are various setups of pytest tests that will actually use the installed version even from the same cwd

@pytoxbot
Copy link
Author

Original comment by @dholth

Oh, there is an option 'changedir'

@obestwalter
Copy link
Member

A lot has happened since then and as @dholth mentioned changedir could be used to that end if needed.

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

No branches or pull requests

2 participants