Created
January 27, 2012 11:29
-
-
Save misaka/1688369 to your computer and use it in GitHub Desktop.
Guardfile for py.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "http://rubygems.org" | |
group :development do | |
gem 'guard' | |
gem 'ruby_gntp' | |
gem 'growl' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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