@@ -730,3 +730,53 @@ def test_script_error_treatment(self):
730730 self .assertIn (
731731 "No such file or directory: 'nonexistent_file.txt'" , output
732732 )
733+
734+ def test_live_incompatible_with_pstats_options (self ):
735+ """Test that --live is incompatible with individual pstats options."""
736+ test_cases = [
737+ (["--sort" , "tottime" ], "--sort" ),
738+ (["--limit" , "30" ], "--limit" ),
739+ (["--no-summary" ], "--no-summary" ),
740+ ]
741+
742+ for args , expected_flag in test_cases :
743+ with self .subTest (args = args ):
744+ test_args = ["profiling.sampling.cli" , "run" , "--live" ] + args + ["test.py" ]
745+ with mock .patch ("sys.argv" , test_args ):
746+ with self .assertRaises (SystemExit ) as cm :
747+ from profiling .sampling .cli import main
748+ main ()
749+ self .assertNotEqual (cm .exception .code , 0 )
750+
751+ def test_live_incompatible_with_multiple_pstats_options (self ):
752+ """Test that --live is incompatible with multiple pstats options."""
753+ test_args = [
754+ "profiling.sampling.cli" , "run" , "--live" ,
755+ "--sort" , "cumtime" , "--limit" , "25" , "--no-summary" , "test.py"
756+ ]
757+
758+ with mock .patch ("sys.argv" , test_args ):
759+ with self .assertRaises (SystemExit ) as cm :
760+ from profiling .sampling .cli import main
761+ main ()
762+ self .assertNotEqual (cm .exception .code , 0 )
763+
764+ def test_live_incompatible_with_pstats_default_values (self ):
765+ """Test that --live blocks pstats options even with default values."""
766+ # Test with --sort=nsamples (the default value)
767+ test_args = ["profiling.sampling.cli" , "run" , "--live" , "--sort=nsamples" , "test.py" ]
768+
769+ with mock .patch ("sys.argv" , test_args ):
770+ with self .assertRaises (SystemExit ) as cm :
771+ from profiling .sampling .cli import main
772+ main ()
773+ self .assertNotEqual (cm .exception .code , 0 )
774+
775+ # Test with --limit=15 (the default value)
776+ test_args = ["profiling.sampling.cli" , "run" , "--live" , "--limit=15" , "test.py" ]
777+
778+ with mock .patch ("sys.argv" , test_args ):
779+ with self .assertRaises (SystemExit ) as cm :
780+ from profiling .sampling .cli import main
781+ main ()
782+ self .assertNotEqual (cm .exception .code , 0 )
0 commit comments