Skip to content
Ian Clark edited this page Oct 14, 2015 · 5 revisions

Anaconda's test runner documentation

The anaconda's test runner is an original contribution by @NorthIsUp.

How to run tests?

You can open the Command Palette and write test until you see the Anaconda: ... test options or just use right click and select the option that you want from the contextual menu.

Available options

  1. Run Last Tests: It will repeat the last test that you run
  2. Run Current Test: It will run the test under the cursor
  3. Run Project Tests: Run the project whole test suite
  4. Run Current File Tests: Run all the tests defined in the current file

Configuration Options

Anaconda test runner support several options to fine tune it's behavior

  • test_before_command: if this option is set, anaconda will try to run the given command before run the test suite (if you need to run more than one command, just use a list of commands ["cmd1", "cmd2", ...])
  • test_after_command: as before, if this option is set, anaconda will try to run the given command (or commands) after run the test suite
  • test_command: the command to run in order to execute the test suite, this is nosetest by default, for example: python -m unittest discover
  • test_delimeter: this is the test delimiter to use after your test module names, by default is :, for example, if you set this to : and your module name is "test_server.py" it will try test_server:ServerTest
  • test_virtualenv: if you need to load a virtual environment to execute your test you can configure it here, anaconda will activate it, run your test, and deactivate it
  • test_project_path: if this options is set, anaconda will add whatever text is on it after the command that is going to be used to run the test suite, this is needed for example to run test suites using the twisted library trial command. For example "test_project_path": "mamba" and trial as configured command will run trial mamba (where mamba is a directory)

Configuration Examples

You can find here some configuration examples in several ways. note: all the configurations are placed in .sublime-project file

Run Twisted's Trial Suite

Normally, to run a test suite built with Twisted's trial you need to pass a top level directory that contains your tests and is used by it's auto test discovery facility.

{
	"build_systems":
	[
		{
			"name": "Anaconda Python Builder",
			"selector": "source.python",
			"shell_cmd": "python -u \"$file\""
		}
	],
	"folders":
	[
		{
			"follow_symlinks": true,
			"path": "."
		}
	],
	"settings": {
            "test_command": "trial",
            "test_delimeter": ".",  // ":" by default
            "test_project_path": "myproject"
	}
}

Test using a virtualenv

{
  "settings": {
    "test_before_command": "source $HOME/.virtualenvs/myproject/bin/activate",
    "test_after_command": "deactivate"
  }
}

Run Twisted's Trial using test_virtualenv (right way)

{
  "settings": {
    "test_command": "trial",
    "test_delimeter": ".",
    "test_project_path": "myproject",
    "test_virtualenv": "$HOME/.virtualenvs/myproject"
  }
}

Django and nose2

  • Apply test_[before/after]_commands to source a virtualenv if required
{
  "settings": {
    "test_command": "./manage.py test --settings=tests.settings --noinput",
    "test_delimeter": "."
  }
}

Common python code and standard library unittest

{
  "settings": {
    "test_command": "python -m unittest discover",
  }
}

Run tests from child directory

Must be an absolute path

{
  "settings": {
    "test_root": "/home/me/project_root/django_root"
  }
}