-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hook for [`pytest`](https://github.com/pytest-dev/pytest), a `python` testing framework. Closes #462.
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Overcommit::Hook::PrePush | ||
# Runs `pytest` test suite before push | ||
# | ||
# @see https://github.com/pytest-dev/pytest | ||
class Pytest < Base | ||
def run | ||
result = execute(command) | ||
return :pass if result.success? | ||
|
||
output = result.stdout + result.stderr | ||
[:fail, output] | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
describe Overcommit::Hook::PrePush::Pytest do | ||
let(:config) { Overcommit::ConfigurationLoader.default_configuration } | ||
let(:context) { double('context') } | ||
subject { described_class.new(config, context) } | ||
|
||
context 'when pytest exits successfully' do | ||
before do | ||
result = double('result') | ||
result.stub(:success?).and_return(true) | ||
subject.stub(:execute).and_return(result) | ||
end | ||
|
||
it { should pass } | ||
end | ||
|
||
context 'when pytest exits unsucessfully' do | ||
before do | ||
result = double('result') | ||
result.stub(:success?).and_return(false) | ||
result.stub(:stdout).and_return('Some error message') | ||
result.stub(:stderr).and_return('') | ||
subject.stub(:execute).and_return(result) | ||
end | ||
|
||
it { should fail_hook 'Some error message' } | ||
end | ||
end |