Skip to content

Commit

Permalink
Add pre-push hook for pytest (#463)
Browse files Browse the repository at this point in the history
Add hook for [`pytest`](https://github.com/pytest-dev/pytest), a
`python` testing framework.

Closes #462.
  • Loading branch information
proinsias authored and trotzig committed Jan 24, 2017
1 parent 2a285fe commit aa599ab
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,12 @@ PrePush:
destructive_only: true
branches: ['master']

Pytest:
enabled: false
description: 'Run pytest test suite'
required_executable: 'pytest'
install_command: 'pip install -U pytest'

RSpec:
enabled: false
description: 'Run RSpec test suite'
Expand Down
14 changes: 14 additions & 0 deletions lib/overcommit/hook/pre_push/pytest.rb
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
29 changes: 29 additions & 0 deletions spec/overcommit/hook/pre_push/pytest_spec.rb
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

0 comments on commit aa599ab

Please sign in to comment.