@@ -947,35 +947,89 @@ def test_run_with_called_process_error(
947
947
tmp_dir : str , tmp_venv : VirtualEnv , mocker : MockerFixture
948
948
):
949
949
mocker .patch (
950
- "subprocess.run" , side_effect = subprocess .CalledProcessError (42 , "some_command" )
950
+ "subprocess.run" ,
951
+ side_effect = subprocess .CalledProcessError (
952
+ 42 , "some_command" , "some output" , "some error"
953
+ ),
951
954
)
952
- with pytest .raises (EnvCommandError ):
955
+ with pytest .raises (EnvCommandError ) as error :
953
956
tmp_venv .run ("python" , "-" , input_ = MINIMAL_SCRIPT )
954
957
subprocess .run .assert_called_once ()
958
+ assert "some output" in str (error .value )
959
+ assert "some error" in str (error .value )
955
960
956
961
957
962
def test_call_with_input_and_called_process_error (
958
963
tmp_dir : str , tmp_venv : VirtualEnv , mocker : MockerFixture
959
964
):
960
965
mocker .patch (
961
- "subprocess.run" , side_effect = subprocess .CalledProcessError (42 , "some_command" )
966
+ "subprocess.run" ,
967
+ side_effect = subprocess .CalledProcessError (
968
+ 42 , "some_command" , "some output" , "some error"
969
+ ),
962
970
)
963
971
kwargs = {"call" : True }
964
- with pytest .raises (EnvCommandError ):
972
+ with pytest .raises (EnvCommandError ) as error :
965
973
tmp_venv .run ("python" , "-" , input_ = MINIMAL_SCRIPT , ** kwargs )
966
974
subprocess .run .assert_called_once ()
975
+ assert "some output" in str (error .value )
976
+ assert "some error" in str (error .value )
967
977
968
978
969
979
def test_call_no_input_with_called_process_error (
970
980
tmp_dir : str , tmp_venv : VirtualEnv , mocker : MockerFixture
971
981
):
972
982
mocker .patch (
973
- "subprocess.call" , side_effect = subprocess .CalledProcessError (42 , "some_command" )
983
+ "subprocess.call" ,
984
+ side_effect = subprocess .CalledProcessError (
985
+ 42 , "some_command" , "some output" , "some error"
986
+ ),
974
987
)
975
988
kwargs = {"call" : True }
976
- with pytest .raises (EnvCommandError ):
989
+ with pytest .raises (EnvCommandError ) as error :
977
990
tmp_venv .run ("python" , "-" , ** kwargs )
978
991
subprocess .call .assert_called_once ()
992
+ assert "some output" in str (error .value )
993
+ assert "some error" in str (error .value )
994
+
995
+
996
+ def test_check_output_with_called_process_error (
997
+ tmp_dir : str , tmp_venv : VirtualEnv , mocker : MockerFixture
998
+ ):
999
+ mocker .patch (
1000
+ "subprocess.check_output" ,
1001
+ side_effect = subprocess .CalledProcessError (
1002
+ 42 , "some_command" , "some output" , "some error"
1003
+ ),
1004
+ )
1005
+ with pytest .raises (EnvCommandError ) as error :
1006
+ tmp_venv .run ("python" , "-" )
1007
+ subprocess .check_output .assert_called_once ()
1008
+ assert "some output" in str (error .value )
1009
+ assert "some error" in str (error .value )
1010
+
1011
+
1012
+ def test_run_python_script_called_process_error (
1013
+ tmp_dir : str , tmp_venv : VirtualEnv , mocker : MockerFixture
1014
+ ):
1015
+ mocker .patch (
1016
+ "subprocess.run" ,
1017
+ side_effect = subprocess .CalledProcessError (
1018
+ 42 , "some_command" , "some output" , "some error"
1019
+ ),
1020
+ )
1021
+ with pytest .raises (EnvCommandError ) as error :
1022
+ tmp_venv .run_python_script (MINIMAL_SCRIPT )
1023
+ assert "some output" in str (error .value )
1024
+ assert "some error" in str (error .value )
1025
+
1026
+
1027
+ def test_run_python_script_only_stdout (tmp_dir : str , tmp_venv : VirtualEnv ):
1028
+ output = tmp_venv .run_python_script (
1029
+ "import sys; print('some warning', file=sys.stderr); print('some output')"
1030
+ )
1031
+ assert "some output" in output
1032
+ assert "some warning" not in output
979
1033
980
1034
981
1035
def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_ones_first ( # noqa: E501
0 commit comments