Skip to content

tox should reuse tests_require from setup.py #13

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

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

tox should reuse tests_require from setup.py #13

pytoxbot opened this issue Sep 17, 2016 · 16 comments
Labels
area:testenv-creation feature:new something does not exist yet, but should level:hard rought estimate that this might be quite hard to implement

Comments

@pytoxbot
Copy link

First, thanks for tox. It is very useful.

I have a setuptools-based setup.py with install_requires, setup_requires and tests_require. I was surprised to find that I needed to duplicate the test dependencies in tox.ini; I checked the doc and many examples from projects I follow and finally asked for confirmation on IRC. Ronny suggested that I report this.

IMO, tox should fetch setup_requires and tests_require dependencies too. This would certainly shorten a lot of people’s tox.ini :)

@pytoxbot
Copy link
Author

Original comment by @merwok

I’m not using setuptools-tests integration at all, so setup.py test would not work. I prefer to tell tox how to run pytest, rather than having a setuptools test command between them.

In my current project I’m using extras rather than tests_require, I could look into overriding the install command to run pip install .[test] and solve my issue.

@pytoxbot
Copy link
Author

Original comment by @brechtm

You could run python {toxinidir}/setup.py test from tox.ini's commands.

@pytoxbot
Copy link
Author

Original comment by @bittner

@@hpk42 This doesn't mean you want to allow setup.cfg as an alternative configuration file, does it? I would love to see this in fact.

Though, tox.ini being the default is rather elegantly solved at config.py, line 269+. I don't see how to fix this without adding at least about 10 lines of code. 😱 Any ideas?

Also, allowing the ini-style sections in setup.py would probably have to entail some design decisions: It could make sense to prefix the sections names with tox: or so, e.g. [tox:testenv] instead of [testenv] in the basic example in the docs. You probably have this envisioned before.

@pytoxbot
Copy link
Author

Original comment by @wosc

My vote goes to Donald's suggestion of supporting setuptools extras from tox.

@pytoxbot
Copy link
Author

Original comment by @dstufft

An alternative way of doing this, is for tox to support adding an extra to the install command. This way extras_requires could be used and tox won't have to "reach into" the setup.py, it would just add some extra stuff to the command to install the package.

@pytoxbot
Copy link
Author

Original comment by @hpk42

Well, i can imagine two principal solutions to sharing tox and setup.py information:

  • generating setup.py from tox information
  • execute setup.py in a monkeypatching way so that we can find out what test_requires etc. it sets (if any).

In both cases, tox needs to become more explicit about the packaging step (currently it's unconditionally performing sdist-packaging). Personally, i am rather interested in generating setup.py (and later pep426 compliant setup.cfg etc.) from tox.ini, so that trove-classifiers, supported platforms, dependencies, become test-verified information and are kept in a non-redundant manner.

@pytoxbot
Copy link
Author

Original comment by sashahart

I'd love to see this fixed in tox. The problem is just getting data out of setup.py. Running setup.py in order to introspect the module or parsing setup.py into an AST seem crazy. Depending on setuptools seems strange at this late date, too. Wouldn't this be better fixed by exposing data in a way which doesn't require running setup.py again, say from the side of distutils2?

@pytoxbot
Copy link
Author

Original comment by @hpk42

sorry, not sure i understand, where would the code accessing "self.distribution.test_require" be located?

@pytoxbot
Copy link
Author

Original comment by @msabramo

I haven't looked at the code for tox, but maybe it could be done in a way such that Tox only installs the test_requires dependencies of the package being tested and not the dependencies of the dependencies. That seems pretty safe in that a person running tox on their own package should be comfortable with whatever it does.

@pytoxbot
Copy link
Author

pytoxbot commented Sep 17, 2016

Original comment by @msabramo

Oops. Forgot to log in.

Would this work?

#!python
        if self.distribution.tests_require:
            self.distribution.fetch_build_eggs(self.distribution.tests_require)

@pytoxbot
Copy link
Author

Original comment by @hpk42

Do you know a safe way to fetch test_requires from setup.py? With static metadata that is doable but with an executable file?

@RonnyPfannschmidt
Copy link

@hpk42 i believe pip does it safely by invoking egg-info with a target directory

@obestwalter obestwalter changed the title tox should reuse tests_require tox should reuse tests_require from setup.py Mar 27, 2017
@obestwalter
Copy link
Member

I would tend to close this as wontfix as we have the extras key now as @dstufft suggested.

@obestwalter obestwalter added area:testenv-creation feature:new something does not exist yet, but should level:hard rought estimate that this might be quite hard to implement and removed enhancement labels Sep 4, 2017
@merwok
Copy link

merwok commented Sep 14, 2017

I don’t object. I don’t use tests_require or setup.py test anywhere, preferring pip requirement files and pytest.

@chrisbarber
Copy link

Why not just make the tox config into a python file instead of ini or TOML, then we can define our tests_require in one location and import it both into tox config as well as setup.py, from this one spot.

@merwok
Copy link

merwok commented Jun 20, 2020

Then you get nox instead of tox 🙂

wmfgerrit pushed a commit to wikimedia/operations-software-wmfmariadbpy that referenced this issue Aug 13, 2020
Requirements were specified in both requirements.txt and setup.py:
- setup.py should be used, as that's what pip looks at when installing
  this as a dependency of something else.

Test requirements where specified in both test-requirements.txt and
setup.py:
- test-requirements.txt should be used, as tox cannot cleanly use
  setup.py for this: tox-dev/tox#13

Change-Id: I0240e16510c2f2cd2c8628aa26c8332f43590faa
@tox-dev tox-dev locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:testenv-creation feature:new something does not exist yet, but should level:hard rought estimate that this might be quite hard to implement
Projects
None yet
Development

No branches or pull requests

5 participants