Skip to content

Commit 16f036e

Browse files
committed
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 --pytest-args="$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.
1 parent 74fa27b commit 16f036e

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

setup.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,20 @@
133133
]
134134

135135

136-
class NoopTestCommand(TestCommand):
137-
def run(self):
138-
print("Matplotlib does not support running tests with "
139-
"'python setup.py test'. Please run 'python tests.py'")
136+
class PyTestCommand(TestCommand):
137+
user_options = [
138+
("pytest-args=", None, "Arguments to pass to pytest"),
139+
("local-freetype", None, "setup.cfg back-compatibility; do not use")]
140+
141+
def initialize_options(self):
142+
TestCommand.initialize_options(self)
143+
self.pytest_args = ""
144+
self.local_freetype = ""
145+
146+
def run_tests(self):
147+
import shlex
148+
import pytest
149+
sys.exit(pytest.main(shlex.split(self.pytest_args)))
140150

141151

142152
class BuildExtraLibraries(BuildExtCommand):
@@ -148,7 +158,7 @@ def run(self):
148158

149159

150160
cmdclass = versioneer.get_cmdclass()
151-
cmdclass['test'] = NoopTestCommand
161+
cmdclass['test'] = PyTestCommand
152162
cmdclass['build_ext'] = BuildExtraLibraries
153163

154164
# One doesn't normally see `if __name__ == '__main__'` blocks in a setup.py,

setupext.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,25 @@ def _get_xdg_cache_dir():
100100
config = configparser.SafeConfigParser()
101101
config.read(setup_cfg)
102102

103-
if config.has_option('status', 'suppress'):
103+
try:
104104
options['display_status'] = not config.getboolean("status", "suppress")
105-
106-
if config.has_option('rc_options', 'backend'):
105+
except configparser.Error:
106+
pass
107+
try:
107108
options['backend'] = config.get("rc_options", "backend")
108-
109-
if config.has_option('directories', 'basedirlist'):
109+
except configparser.Error:
110+
pass
111+
try:
110112
options['basedirlist'] = [
111113
x.strip() for x in
112114
config.get("directories", "basedirlist").split(',')]
113-
114-
if config.has_option('test', 'local_freetype'):
115-
options['local_freetype'] = config.getboolean("test", "local_freetype")
115+
except configparser.Error:
116+
pass
117+
try:
118+
options['local_freetype'] = config.getboolean(
119+
"test_build", "local_freetype")
120+
except configparser.Error:
121+
pass
116122
else:
117123
config = None
118124

0 commit comments

Comments
 (0)
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