8000 setup.py test as test entry point. by anntzer · Pull Request #8135 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

setup.py test as test entry point. #8135

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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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 `s
10000
etup.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.
  • Loading branch information
anntzer committed Sep 21, 2017
commit 9b8d3df3b56a8225c20879ed1df8c65fe55e165f
21 changes: 16 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down
22 changes: 14 additions & 8 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
0