@@ -135,7 +135,11 @@ See also https://github.com/LinuxSuRen/api-testing/tree/master/sample`,
135135const caseFilter = "case-filter"
136136
137137func (o * runOption ) preRunE (cmd * cobra.Command , args []string ) (err error ) {
138- o .context = context .WithValue (cmd .Context (), caseFilter , o .caseFilter )
138+ ctx := o .context
139+ if ctx == nil {
140+ ctx = context .Background ()
141+ }
142+ o .context = context .WithValue (ctx , caseFilter , o .caseFilter )
139143 writer := cmd .OutOrStdout ()
140144
141145 if o .reportFile != "" && ! strings .HasPrefix (o .reportFile , "http://" ) && ! strings .HasPrefix (o .reportFile , "https://" ) {
@@ -349,7 +353,10 @@ func (o *runOption) runSuite(loader testing.Loader, dataContext map[string]inter
349353 suiteRunner .WithOutputWriter (os .Stdout )
350354 suiteRunner .WithWriteLevel (o .level )
351355 suiteRunner .WithSuite (testSuite )
352- caseFilter := o .context .Value (caseFilter )
356+ var caseFilter interface {}
357+ if o .context != nil {
358+ caseFilter = o .context .Value (caseFilter )
359+ }
353360 runLogger .Info ("run test suite" , "name" , testSuite .Name , "filter" , caseFilter )
354361 for _ , testCase := range testSuite .Items {
355362 if caseFilter != nil && ! strings .Contains (testCase .Name , caseFilter .(string )) {
0 commit comments