Continuous unit testing with Pydev (Python and Eclipse)

Is there a way to integrate background tests in Pydev Eclipse?

My unit tests work well, but I would like to integrate them in the background based on changes to the source file (e.g. with a nose) and integrate the result back into Eclipse (I think big red X when tests do not work with console viewing and tracing) .

No, a command tip that carries a nose on the side does not count.

I had this Eclipse integration when developing RoR data.

Thank,

Tal.

EDIT: Check out the new Pydev (1.6.4) http://pydev.org/manual_adv_pyunit.html

+42
python unit-testing pydev
Jun 18 '09 at 22:46
source share
6 answers

This feature was added in PyDev 2.0.1 with the ability to restart the tests in the last test run whenever the python file changes, with an additional option to restart only errors - although it will run a full test if no errors are detected, because the idea is that you are working with your errors and when everyone goes through the final launch for the whole package (then you can move on to another task).

The current nightly build has this feature enabled.

Picture with new action

+34
Apr 13 2018-11-11T00:
source share

Pydev has some test integration, but only as a launch configuration ... so ...

This is not a very elegant way, but if you:

  • Enable Project-> Build Automatically
  • In the project properties add a new builder of type Program
  • Configure it to run tests and select "during automatic build"

Then at least you get what displays the test results on the console while saving the resource.

+9
Jun 24 '09 at 16:44
source share

I just realized that PyDev has pretty powerful script support. Unfortunately, I don’t have time to do everything for you (but if you fill it out, write here :)

If you create a file called pyedit_nose.py that looks like this in an empty folder:

 assert cmd is not None assert editor is not None if cmd == 'onSave': from java.lang import Runtime from java.io import BufferedReader from java.io import InputStreamReader from org.eclipse.core.resources import ResourcesPlugin from org.eclipse.core.resources import IMarker from org.eclipse.core.resources import IResource proc = Runtime.getRuntime().exec('ls -al') extra_message = BufferedReader(InputStreamReader(proc.inputStream)).readLine() r = ResourcesPlugin.getWorkspace().getRoot() for marker in r.findMarkers(IMarker.PROBLEM, False, IResource.DEPTH_INFINITE): if marker.getAttribute(IMarker.MESSAGE).startsWith("Some test failed!"): marker.delete() for rr in r.getProjects(): marker = rr.createMarker(IMarker.PROBLEM) marker.setAttribute(IMarker.MESSAGE, "Some test failed! " + extra_message) marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH) marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR) 

and configure Preferences-> PyDev-> Scripting Pydev to point to this directory, you will get all projects in your workspace marked with an error every time the file is saved.

By executing a script that returns the test results in some simple format analysis, not ls and parses the output, you should put the markers in the right places.

Take a look at some starting points:

  • Jython Scripting in Pydev
  • IMarker is what a marker represents.
  • IResource is what you attach your markers to. There may be workspaces, projects, files, directories, etc. resource.createMarker(IMarker.PROBLEM) creates a problem marker.
  • IProject is an IResource type that represents a project. Use the members() method to get the content.
+5
Jun 24 '09 at 19:16
source share

I am using Nosy (available on pypi):

Run the nose test detection and execution tool when the source file changes.

0
Apr 08 '10 at 2:51
source share

I improved the "nody" script to automatically create documentation and run tests continuously. Nothing stellar, but it does its job. Spending it here because the original link has dropped. Unlike the original nosy script, this one scans the directory recursively and allows you to search for multiple templates.

 import os import os.path import sys import stat import time import subprocess from fnmatch import fnmatch def match_patterns(pathname, patterns): """Returns True if the pathname matches any of the given patterns.""" for pattern in patterns: if fnmatch(pathname, pattern): return True return False def filter_paths(pathnames, patterns=["*"], ignore_patterns=[]): """Filters from a set of paths based on acceptable patterns and ignorable patterns.""" result = [] if patterns is None: patterns = [] if ignore_patterns is None: ignore_patterns = [] for path in pathnames: if match_patterns(path, patterns) and not match_patterns(path, ignore_patterns): result.append(path) return result def absolute_walker(path, recursive): if recursive: walk = os.walk else: def walk(path): return os.walk(path).next() for root, directories, filenames in walk(path): yield root for directory in directories: yield os.path.abspath(os.path.join(root, directory)) for filename in filenames: yield os.path.abspath(os.path.join(root, filename)) def glob_recursive(path, patterns=["*"], ignore_patterns=[]): full_paths = [] for root, directories, filenames in os.walk(path): for filename in filenames: full_path = os.path.abspath(os.path.join(root, filename)) full_paths.append(full_path) filepaths = filter_paths(full_paths, patterns, ignore_patterns) return filepaths def check_sum(path='.', patterns=["*"], ignore_patterns=[]): sum = 0 for f in glob_recursive(path, patterns, ignore_patterns): stats = os.stat(f) sum += stats[stat.ST_SIZE] + stats[stat.ST_MTIME] return sum if __name__ == "__main__": if len(sys.argv) > 1: path = sys.argv[1] else: path = '.' if len(sys.argv) > 2: command = sys.argv[2] else: command = "make -C docs html; bin/python tests/run_tests.py" previous_checksum = 0 while True: calculated_checksum = check_sum(path, patterns=['*.py', '*.rst', '*.rst.inc']) if calculated_checksum != previous_checksum: previous_checksum = calculated_checksum subprocess.Popen(command, shell=True) time.sleep(2) 

Hope this helps.

=)

0
Dec 02 '10 at 18:29
source share

I run the test manually (Run> Run As> Python unit test). After that, I use Ctrl+Shift+F9 to save the files and run the tests instead of saving with Ctrl+S and expect some kind of magic to happen.

The key combination Ctrl+Shift+F9 resumes the configuration of the last run.

Disclaimer I am new to Eclipse and PyDev, so I can offer something stupid / obvious / wrong

0
Feb 21 2018-11-21T00:
source share



All Articles