8000 setup.py test as test entry point. · matplotlib/matplotlib@aa209ff · GitHub
[go: up one dir, main page]

Skip to content

Commit aa209ff

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 -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.
1 parent db9e631 commit aa209ff

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

setup.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,21 @@
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=", "a", "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+
errno = pytest.main(shlex.split(self.pytest_args))
150+
sys.exit(errno)
140151

141152

142153
class BuildExtraLibraries(BuildExtCommand):
@@ -148,7 +159,7 @@ def run(self):
148159

149160

150161
cmdclass = versioneer.get_cmdclass()
151-
cmdclass['test'] = NoopTestCommand
162+
cmdclass['test'] = PyTestCommand
152163
cmdclass['build_ext'] = BuildExtraLibraries
153164

154165
# 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)
0