Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[suite] Should testify.Suite run all tests from the sub suite in the case when passed -testify.m flag? #1050

Open
denis-tingaikin opened this issue Feb 11, 2021 · 3 comments · May be fixed by #1051

Comments

@denis-tingaikin
Copy link

denis-tingaikin commented Feb 11, 2021

Hello guys,

We've found one funny thing about suite.Run. It allows running inner suites (that look awesome to me :) ). But this working some strange if passed testify.m parameter.

For example:

package mypkg_test

import "github.com/stretchr/testify/suite"

type suite1 struct{
    suite.Suite
}

func (s *suite1) Test1() {
    println("test1")
}

type suite2 struct{
    suite.Suite
}

func (s *suite2) Test2() {
    suite.Run(s.T(), new(suite1))
}

func TestSuite2(t *testing.T) {
    suite.Run(t, new(suite2))
}

So if I just run TestSuite2 then it works fine (suite2 runs all tests from suite1).
But if I run TestSuite2 with paramter -testify.m="Test2" then suite1 will be ignored.

Please share your thoughts about:

  1. Is sub suites legal?
  2. Should the matching filter ignore sub suites?
@denis-tingaikin denis-tingaikin changed the title [Question] Should testify.Suite run all tests from the inner suite in the case when passed -testify.m flag? [Question] [suite] Should testify.Suite run all tests from the inner suite in the case when passed -testify.m flag? Feb 11, 2021
@denis-tingaikin
Copy link
Author

Potential fix: #1051

@boyan-soubachov
Copy link
Collaborator

boyan-soubachov commented Feb 15, 2021

Looking at the description of the testify.m parameter, it's meant to match tests rather than suites. The behaviour that you have noticed therefore seems correct to me.

Also, changing this would necessitate a breaking change and therefore would be merged in v2 at the earliest.

@denis-tingaikin denis-tingaikin changed the title [Question] [suite] Should testify.Suite run all tests from the inner suite in the case when passed -testify.m flag? [Question] [suite] Should testify.Suite run all tests from the sub suite in the case when passed -testify.m flag? Feb 15, 2021
@denis-tingaikin
Copy link
Author

denis-tingaikin commented Feb 15, 2021

@boyan-soubachov OK,
Do you have an idea about a pure fix for the issue?

I see these solutions:

  1. Add a custom filter option as it has done in feat: allow passing custom test filter function for suites #1051.
  2. Add an additional flag that will represent something like suite name regex. If the flag is passed then the flag with test matching will be applying only for the passed suite. For example: go test ./... -testify.m="Test1" -testify.s="Suite1" will mean something like: run all tests but for suite1 run only Test1.
  3. Apply to testify.m flag only for top-level suites
  4. Add an alternative flag that will expect a go-template string. With go-templates testify could support more interesting filters.
  5. Your solution :)

@denis-tingaikin denis-tingaikin changed the title [Question] [suite] Should testify.Suite run all tests from the sub suite in the case when passed -testify.m flag? [suite] Should testify.Suite run all tests from the sub suite in the case when passed -testify.m flag? Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants