From 0fecb80e41a648f84e700b3afce0c33bebde22f2 Mon Sep 17 00:00:00 2001 From: Branko Majic Date: Wed, 14 Feb 2018 16:22:38 +0100 Subject: [PATCH] Remove runtests.py and run pytest directly (issue #644): - Removed the runtests.py script. - Updated manifest file to not include the removed script. - Updated documentation to reference to direct use of the pytest command. - Updated tox configuration to run pytest directly. - Added documentation for the SELENIUM_SHOW_BROWSER environment variable. - Updated testing documentation to mention that Xvfb must be available on the system as well for runing Selenium tests. --- MANIFEST.in | 1 - Makefile | 2 +- docs/development/testing.rst | 23 ++++++++++---- runtests.py | 58 ------------------------------------ tox.ini | 2 +- 5 files changed, 19 insertions(+), 67 deletions(-) delete mode 100755 runtests.py diff --git a/MANIFEST.in b/MANIFEST.in index e85d373c..e8e79223 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,6 @@ include COPYING include README.rst include setup.cfg -include runtests.py recursive-include src *.html *.txt *.png *.js *.css *.gif *.less *.mo *.po *.otf *.svg *.woff *.woff2 *.eot *.ttf prune src/wiki/attachments prune src/wiki/images diff --git a/Makefile b/Makefile index 3637ed2e..99d31f7d 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ lint: ## Check python code conventions flake8 src/wiki tests/ test: ## Run automated test suite - ./runtests.py + pytest test-all: ## Run tests on all supported Python environments tox diff --git a/docs/development/testing.rst b/docs/development/testing.rst index f0d945e1..59f9faf0 100644 --- a/docs/development/testing.rst +++ b/docs/development/testing.rst @@ -4,19 +4,30 @@ Tests Running tests ------------- -To run django-wiki's tests, run ``make test`` or ``./runtests.py`` +To run django-wiki's tests, run ``make test`` or ``pytest`` If you want to test for more **environments**, install "tox" (``pip install tox``) and then just run ``tox`` to run the test suite on multiple environments. -To run **specific tests**, see ``./runtests.py --help``. +To run **specific tests**, see ``pytest --help``. -To include Selenium tests, you need to install `chromedriver -`_ and run -``./runtests.py --include-selenium``. For tox, do:: +To include Selenium tests, you need to have ``Xvfb`` installed +(usually via system-provided package manager), `chromedriver +`_ and set the +environment variable ``INCLUDE_SELENIUM_TESTS=1``. For example, run +tests with (depending on whether you want to test directly or via +tox):: - INCLUDE_SELENIUM_TESTS=1 tox + INCLUDE_SELENIUM_TESTS=1 pytest + INCLUDE_SELENIUM_TESTS=1 tox + +If you wish to also show the browser window while running the +functional tests, set the environment variable +``SELENIUM_SHOW_BROWSER=1`` in *addition* to +``INCLUDE_SELENIUM_TESTS=1``, for example:: + + INCLUDE_SELENIUM_TESTS=1 SELENIUM_SHOW_BROWSER=1 pytest Writing tests diff --git a/runtests.py b/runtests.py deleted file mode 100755 index 2e89bdef..00000000 --- a/runtests.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python -from __future__ import print_function, unicode_literals - -import argparse -import os -import signal -import subprocess -import sys - - -class RuntestsArgumentParser(argparse.ArgumentParser): - def print_help(self): - super(RuntestsArgumentParser, self).print_help() - print("\n") - print("All other arguments will be passed to pytest, \n" - "which has the following options:\n") - subprocess.call(["pytest", "--help"]) - -parser = RuntestsArgumentParser(usage="./runtests.py [args] [tests to run]\n\n" - "Individual tests can be run using pytest syntax e.g.\n\n" - " ./runtests.py ./tests/core/test_views.py::ArticleViewViewTests::test_article_list_update\n") -parser.add_argument("--include-selenium", action='store_true', - help="Include Selenium tests, which are skipped by default. Requires chromedriver") -parser.add_argument("--show-browser", action='store_true', - help="Show browser window when running Selenium tests") - - -def main(): - known_args, remaining_args = parser.parse_known_args() - cmd = ["pytest"] + remaining_args - if known_args.include_selenium: - # It is easier to use environment variables than to use 'pytest -k', - # because the user might want to use that option. - os.environ['INCLUDE_SELENIUM_TESTS'] = "1" - if known_args.show_browser: - os.environ['SELENIUM_SHOW_BROWSER'] = "1" - - # Signal handling to ensure the right thing happens - # when Ctrl-C is pressed. - SIGINT_RECEIVED = False - - def signal_handler(sig, f): - global SIGINT_RECEIVED - SIGINT_RECEIVED = True - # No other action, just allow child to exit. - - - signal.signal(signal.SIGINT, signal_handler) - - retcode = subprocess.call(cmd) - - if SIGINT_RECEIVED: - sys.exit(1) - else: - sys.exit(retcode) - -if __name__ == '__main__': - main() diff --git a/tox.ini b/tox.ini index 87333b3d..3d259f05 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,7 @@ commands = # Test that there are no migrations needed -- on Django 1.11, we can # use --check and remove the '!' which likely doesn't work on Windows sh -c '! testproject/manage.py makemigrations --dry-run --exit --noinput' - {toxinidir}/runtests.py --basetemp={envtmpdir} --ds=tests.settings --cov=src/wiki --cov-config .coveragerc {posargs} + pytest --basetemp={envtmpdir} --ds=tests.settings --cov=src/wiki --cov-config .coveragerc {posargs} usedevelop = true -- 2.45.2