Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Ensure the test suite is executed against the local tornado modules. #545

Closed
wants to merge 5 commits into from

3 participants

@birknilson

In case tornado is installed globally on the system, i.e in site-packages, it will compromise our execution of tornado/test/runtests.py. Because the global version of tornado will be imported instead of the local one in which the executed runtests.py script resides.

This pull request resolves this issue by injecting the local tornado directory path to our sys.path prior to importing any tornado modules in the runtests.py script. The path is inserted at index 1 since the current directory should remain the primary one.

@birknilson birknilson Ensure the test suite is executed against the local tornado modules.
This is achieved by injecting the path of the tornado module in which
the test suite is located in our sys.path.
9d24495
@bdarnell
Owner

This is why I prefer the python -m style of running python programs. It guarantees a consistent set of modules, and in a little-known twist adds the current directory to the PYTHONPATH. I'm reluctant to add explicit sys.path manipulation in code; it's come back to bite me too often.

@birknilson

I agree the best solution is to execute the script with the -m flag. However, I do think we could add a simple bash script which invokes the runtests.py script with the -m flag. Which could reside under tornado/test/run for instance and be the recommended endpoint to execute the test suite - which would be specified by the documentation instead of the current runtests.py.

I execute the test suite too often without -m since the script itself has the necessary shebang and permissions to execute it directly without invoking python -m. It's too easy to trick oneself into believing everything works :)

@alekstorm

+1 for the dedicated bash script, but should be called runtests and live in the toplevel directory of the repository.

@birknilson

I have now changed this pull request to utilize a newly introduced bash script instead of the prior sys.path manipulation. The bash script is named and placed according to @alekstorm's suggestion and it merely executes the runtests.py script, but as a module using the python -m invokation.

This solution will not break any existing scripts people might have constructed to automatically execute the runtests.py script & it will work in the same way as before. However, the runtests bash script will ensure local modules are imported and is therefore the recommended script to utilize during development & testing. The relevant docstrings in the testing module has been changed to reflect this and promote the new bash alternative.

@alekstorm

LGTM, but I meant the toplevel directory of the repository (tornado contains source files and gets copied to the user's site-packages directory). As in, make this script a sibling of tornado. That way, the entirety of the script can be:

#!/usr/bin/env bash
python -m tornado.test.runtests $*

How do other projects do this?

@bdarnell bdarnell closed this pull request from a commit
@bdarnell bdarnell Encourage "python -m tornado.test.runtests" as the way to run the tests.
Remove execute bit from tornado/test/runtests.py, which would unexpectedly
run the tests from a globally-installed version of tornado when run directly.
Add a new runtests.sh to make the recommended behavior more discoverable.
Remove run_pyversion_tests.py, which has been superceded by tox.
Update docs.

Closes #545.
ef9df4d
@bdarnell bdarnell closed this in ef9df4d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 20, 2012
  1. @birknilson

    Ensure the test suite is executed against the local tornado modules.

    birknilson authored
    This is achieved by injecting the path of the tornado module in which
    the test suite is located in our sys.path.
Commits on Jun 21, 2012
  1. @birknilson
  2. @birknilson

    Added bash script which will execute the entire test suite.

    birknilson authored
    This script will ensure to execute the test suite against the local
    tornado modules in which the script itself resides rather than any
    system wide installation.
  3. @birknilson
  4. @birknilson
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 2 deletions.
  1. +19 −0 tornado/runtests
  2. +2 −2 tornado/testing.py
View
19 tornado/runtests
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+#
+# Execute the entire tornado test suite and ensure the local tornado
+# modules are imported rather than the system wide packages.
+#
+
+# Retrieve the absolute path of the root tornado directory
+# in which this script is located.
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
+TORNADO_ROOT_DIR="$( cd -P "$( dirname "$SOURCE" )/../" && pwd )"
+
+# Change directory to the root tornado directory
+cd $TORNADO_ROOT_DIR
+
+# Execute the entire test suite script as a module.
+# All arguments passed to this script will be passed along to the
+# tornado.test.runtests module.
+python -m tornado.test.runtests $*
View
4 tornado/testing.py
@@ -388,9 +388,9 @@ def main():
be overridden by naming a single test on the command line::
# Runs all tests
- tornado/test/runtests.py
+ tornado/runtests
# Runs one test
- tornado/test/runtests.py tornado.test.stack_context_test
+ tornado/runtests tornado.test.stack_context_test
"""
from tornado.options import define, options, parse_command_line
Something went wrong with that request. Please try again.