Skip to content

Commit aa599ab

Browse files
proinsiastrotzig
authored andcommitted
Add pre-push hook for pytest (sds#463)
Add hook for [`pytest`](https://github.com/pytest-dev/pytest), a `python` testing framework. Closes sds#462.
1 parent 2a285fe commit aa599ab

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

config/default.yml

+6
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,12 @@ PrePush:
900900
destructive_only: true
901901
branches: ['master']
902902

903+
Pytest:
904+
enabled: false
905+
description: 'Run pytest test suite'
906+
required_executable: 'pytest'
907+
install_command: 'pip install -U pytest'
908+
903909
RSpec:
904910
enabled: false
905911
description: 'Run RSpec test suite'
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Overcommit::Hook::PrePush
2+
# Runs `pytest` test suite before push
3+
#
4+
# @see https://github.com/pytest-dev/pytest
5+
class Pytest < Base
6+
def run
7+
result = execute(command)
8+
return :pass if result.success?
9+
10+
output = result.stdout + result.stderr
11+
[:fail, output]
12+
end
13+
end
14+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PrePush::Pytest do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
context 'when pytest exits successfully' do
9+
before do
10+
result = double('result')
11+
result.stub(:success?).and_return(true)
12+
subject.stub(:execute).and_return(result)
13+
end
14+
15+
it { should pass }
16+
end
17+
18+
context 'when pytest exits unsucessfully' do
19+
before do
20+
result = double('result')
21+
result.stub(:success?).and_return(false)
22+
result.stub(:stdout).and_return('Some error message')
23+
result.stub(:stderr).and_return('')
24+
subject.stub(:execute).and_return(result)
25+
end
26+
27+
it { should fail_hook 'Some error message' }
28+
end
29+
end

0 commit comments

Comments
 (0)