Skip to content

Instantly share code, notes, and snippets.

@misaka
Created January 27, 2012 11:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misaka/1688369 to your computer and use it in GitHub Desktop.
Save misaka/1688369 to your computer and use it in GitHub Desktop.
Guardfile for py.test
source "http://rubygems.org"
group :development do
gem 'guard'
gem 'ruby_gntp'
gem 'growl'
end
# -*- mode: ruby -*-
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
require 'guard/guard'
notification :growl
module ::Guard
class Pytest < ::Guard::Guard
def run_all
system "py.test -q tests"
end
def run_on_change(paths)
test_files = paths.reject { |path| path.match %r{^tests/} }.inject( [] ) do |test_files, path|
dir = File.dirname( path )
dirs = dir.split( '/' )
filename = File.basename( path )
[
"tests/#{dir}/test_#{filename}",
"tests/test_" + ( dirs ).join( '_' ) + '_' + filename,
"#{dir}/test/test_#{filename}"
].select do |pattern|
test_files << pattern if File.exists? pattern
end
end
test_files += paths.grep( %r{^tests/} )
output = `py.test -q #{test_files.join(' ')}`
puts output
# Send out a notification (via Growl, etc).
result_match = output.match( /\n.*seconds$/ )
result = result_match ? result_match[0] : "unknown failure"
image = result.match( /fail/ ) ? :failed : :success
::Guard::Notifier.notify( result, :title => "PyTest Results", :image => image )
end
end
end
guard :py_test do
watch( %r{^dataguru/.*.py$} )
watch( %r{^tests/.*.py$} )
watch( 'tests/conftest.py' ) { Dir['tests/**/test*.py'] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment