@@ -569,49 +569,55 @@ names the cause.`,
569569 cmd .SetFlagErrorFunc (testFlagErrorFunc )
570570
571571 cmd .RunE = func (cmd * cobra.Command , args []string ) error {
572- if cmd .ArgsLenAtDash () >= 0 {
573- return errors .New ("the -- separator is not supported: " + pytestArgHint )
574- }
575- if root .OutputType (cmd ) != flags .OutputText {
576- return fmt .Errorf ("--output %s is not supported by pipelines test" , root .OutputType (cmd ))
577- }
578- if err := validatePytestArgs (pytestArgs ); err != nil {
579- return err
580- }
581- if timeout < 0 {
582- return errors .New ("--timeout must not be negative" )
583- }
584- if noWait && timeout > 0 {
585- return errors .New ("--timeout cannot be used with --no-wait" )
586- }
587- if noWait && junitPath != "" {
588- return errors .New ("--junit-xml cannot be used with --no-wait because no results are available when the command returns" )
589- }
590572 // An empty --resume, such as from an unset shell variable, must not start a new run.
591573 resume := cmd .Flags ().Changed ("resume" )
592- if resume {
593- selectionCount := len (args )
594- if pipelineID == "" {
595- selectionCount = max (len (args )- 1 , 0 )
574+ checkFlags := func () error {
575+ if cmd .ArgsLenAtDash () >= 0 {
576+ return errors .New ("the -- separator is not supported: " + pytestArgHint )
596577 }
597- switch {
598- case noWait :
599- return errors .New ("--resume cannot be used with --no-wait" )
600- case len (pytestArgs ) > 0 :
601- return errors .New ("--resume cannot be used with --pytest-arg" )
602- case selectionCount > 0 :
603- return errors .New ("--resume cannot be used with test selections" )
578+ if root .OutputType (cmd ) != flags .OutputText {
579+ return fmt .Errorf ("--output %s is not supported by pipelines test" , root .OutputType (cmd ))
604580 }
605- if _ , err := uuid . Parse ( resumeUpdateID ); err != nil {
606- return fmt . Errorf ( "--resume %q is not an update ID; pass the update ID that pipelines test printed" , resumeUpdateID )
581+ if err := validatePytestArgs ( pytestArgs ); err != nil {
582+ return err
607583 }
584+ if timeout < 0 {
585+ return errors .New ("--timeout must not be negative" )
586+ }
587+ if noWait && timeout > 0 {
588+ return errors .New ("--timeout cannot be used with --no-wait" )
589+ }
590+ if noWait && junitPath != "" {
591+ return errors .New ("--junit-xml cannot be used with --no-wait because no results are available when the command returns" )
592+ }
593+ if resume {
594+ selectionCount := len (args )
595+ if pipelineID == "" {
596+ selectionCount = max (len (args )- 1 , 0 )
597+ }
598+ switch {
599+ case noWait :
600+ return errors .New ("--resume cannot be used with --no-wait" )
601+ case len (pytestArgs ) > 0 :
602+ return errors .New ("--resume cannot be used with --pytest-arg" )
603+ case selectionCount > 0 :
604+ return errors .New ("--resume cannot be used with test selections" )
605+ }
606+ if _ , err := uuid .Parse (resumeUpdateID ); err != nil {
607+ return fmt .Errorf ("--resume %q is not an update ID; pass the update ID that pipelines test printed" , resumeUpdateID )
608+ }
609+ }
610+ return nil
608611 }
609612
610- // From here on, every exit writes the report, so that an older report never survives.
613+ // Every exit writes the report, so that an older report never survives.
611614 report := & testReport {path : junitPath , out : cmd .OutOrStdout (), suiteName : pipelineID }
612615 if report .suiteName == "" && len (args ) > 0 {
613616 report .suiteName = args [0 ]
614617 }
618+ if err := checkFlags (); err != nil {
619+ return report .failed (cmd .Context (), err )
620+ }
615621
616622 var target testTarget
617623 var err error
0 commit comments