File tree 3 files changed +49
-0
lines changed
lib/overcommit/hook/pre_push
spec/overcommit/hook/pre_push
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -900,6 +900,12 @@ PrePush:
900
900
destructive_only : true
901
901
branches : ['master']
902
902
903
+ Pytest :
904
+ enabled : false
905
+ description : ' Run pytest test suite'
906
+ required_executable : ' pytest'
907
+ install_command : ' pip install -U pytest'
908
+
903
909
RSpec :
904
910
enabled : false
905
911
description : ' Run RSpec test suite'
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments