From 9b8d3df3b56a8225c20879ed1df8c65fe55e165f Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 22 Feb 2017 21:49:55 -0800 Subject: [PATCH 1/2] setup.py test as test entry point. This is a proof of concept that `python setup.py test` can be used as entry point to the test suite. `python setup.py test` will build matplotlib and run `pytest` locally. There is no need to install matplotlib in a venv, `setup.py test` apparently handles `PYTHONPATH` itself (and even the `mpl_toolkits` namespace package seems to be handled properly). (In my opinion, this is an unexpected big plus.) The `test` section of `setup.cfg` had to be renamed to `test_build` as it is otherwise interpreted as an option passed to `setup.py test`, which it is not, right now. It may be advantageous to make setup.py test --local-freetype=true "work", but this would require more refactoring as `setupext` is currently imported, and thus the choice of whether to use a local freetype done, at the top of `setup.py`, before we know whether we are going to run the test suite. This needs to be documented. Arguments to `pytest` are passed as python setup.py test -a "$PYTEST_ARGS" (as `setup.py` will swallow unspecified arguments itself). The remaining setups in `tests.py` are setting the recursion limit and turning on some deprecation warnings. I think the former can be implemented as a local pytest plugin, and the latter as a session-scoped fixture. If we switch to this method, the CI scripts would need to be adjusted as well. The implementation is essentially copy-pasted from http://doc.pytest.org/en/latest/goodpractices.html#manual-integration. --- setup.py | 21 ++++++++++++++++----- setupext.py | 22 ++++++++++++++-------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/setup.py b/setup.py index 95e05a67d258..213976c31d22 100644 --- a/setup.py +++ b/setup.py @@ -132,10 +132,21 @@ ] -class NoopTestCommand(TestCommand): - def run(self): - print("Matplotlib does not support running tests with " - "'python setup.py test'. Please run 'python tests.py'") +class PyTestCommand(TestCommand): + user_options = [ + ("pytest-args=", "a", "Arguments to pass to pytest"), + ("local-freetype", None, "setup.cfg back-compatibility; do not use")] + + def initialize_options(self): + TestCommand.initialize_options(self) + self.pytest_args = "" + self.local_freetype = "" + + def run_tests(self): + import shlex + import pytest + errno = pytest.main(shlex.split(self.pytest_args)) + sys.exit(errno) class BuildExtraLibraries(BuildExtCommand): @@ -147,7 +158,7 @@ def run(self): cmdclass = versioneer.get_cmdclass() -cmdclass['test'] = NoopTestCommand +cmdclass['test'] = PyTestCommand cmdclass['build_ext'] = BuildExtraLibraries # One doesn't normally see `if __name__ == '__main__'` blocks in a setup.py, diff --git a/setupext.py b/setupext.py index 1b03b4d93bf2..5c893a805904 100644 --- a/setupext.py +++ b/setupext.py @@ -100,19 +100,25 @@ def _get_xdg_cache_dir(): config = configparser.SafeConfigParser() config.read(setup_cfg) - if config.has_option('status', 'suppress'): + try: options['display_status'] = not config.getboolean("status", "suppress") - - if config.has_option('rc_options', 'backend'): + except configparser.Error: + pass + try: options['backend'] = config.get("rc_options", "backend") - - if config.has_option('directories', 'basedirlist'): + except configparser.Error: + pass + try: options['basedirlist'] = [ x.strip() for x in config.get("directories", "basedirlist").split(',')] - - if config.has_option('test', 'local_freetype'): - options['local_freetype'] = config.getboolean("test", "local_freetype") + except configparser.Error: + pass + try: + options['local_freetype'] = config.getboolean( + "test_build", "local_freetype") + except configparser.Error: + pass else: config = None From 86dc98d7672ce64a4d6368c7dffe415d82f150dc Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 20 Sep 2017 23:04:58 -0700 Subject: [PATCH 2/2] Do not install any dependency from setup.py test. If we did not overrider install_dists, setup.py test would install dependencies using easy_install, which we definitely do not want. --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 213976c31d22..cd0eb52e47d9 100644 --- a/setup.py +++ b/setup.py @@ -142,6 +142,8 @@ def initialize_options(self): self.pytest_args = "" self.local_freetype = "" + install_dists = staticmethod(lambda dist: []) + def run_tests(self): import shlex import pytest pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy