-
-
Notifications
You must be signed in to change notification settings - Fork 665
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
Support Labels (and label-filtering) on BeforeSuite/BeforeAll/BeforeEach #1119
Comments
Hey! Yes there is a workaround though it isn't currently very elegant. You can do something like this: BeforeSuite(func() {
//first - get the Ginkgo Suite Configuration
suiteConfig, _ := GinkgoConfiguration()
//suiteConfig.LabelFilter is a string containing the label filters that were passed in with `ginkgo --label-filter=X` we can parse it with `types.ParseLabelFilter()` from `github.com/onsi/ginkgo/v2/types`
labelFilter, err := types.ParseLabelFilter(suiteConfig.LabelFilter)
Expect(err).NotTo(HaveOccurred())
//labelFilter is now a function that takes []string (a slice of labels) and returns a bool if those labels pass the filter. you could do:
if labelFilter([]string{"slow"}) {
// do slow setup
}
if labelFilter([]string{"fast"}) {
// do fast setup
}
}) One limitation of this approach, however, is that it won't work if you do something like |
Thanks @onsi . |
What I could add is a method to
Or possibly even add a new top level function:
but that would be the extent of the integration. Is that what you're imagining? |
@onsi top level function looks good to me! |
hey @tzvatot here's what it ended up looking like:
Putting this together you can do: BeforeSuite(func() {
if matches, err := Label("slow").MatchesLabelFilter(GinkgoLabelFilter()); matches && err == nil {
// do slow setup
}
if matches, err := Label("fast").MatchesLabelFilter(GinkgoLabelFilter()); matches && err == nil {
// do fast setup
}
}) the error handling is a bit noisy but the reality is that the label filter could fail to parse so the error is necessary. |
Actually, never mind - that design is dumb given the context. I've made it so that BeforeSuite(func() {
if Label("slow").MatchesLabelFilter(GinkgoLabelFilter()) {
// do slow setup
}
if Label("fast").MatchesLabelFilter(GinkgoLabelFilter()) {
// do fast setup
}
}) when I cut the release |
This is now in Ginkgo 2.8.0 |
Thanks @onsi ! |
Previously we matched on the labels of the current spec as opposed to the label filter passed in from the CLI. This commit uses the correct syntax as per ginkgo: onsi/ginkgo#1119 (comment)
Previously we matched on the labels of the current spec as opposed to the label filter passed in from the CLI. This commit uses the correct syntax as per ginkgo: onsi/ginkgo#1119 (comment)
There are some tests that are labeled, for example as "slow" test or "fast" test.
The initialization is done in BeforeSuite, for both types of tests.
It means that when running "fast" test, the initialization of the slow tests is also running.
We can move the slow test initialization to it's own file, but then, when we will run "slow" tests, it will still run any initialization in the BeforeSuite (i.e. all the fast tests initialization).
Generally speaking, initialization (done in BeforeSuite) can be related to group of tests, the same way as tests are labeled.
BeforeSuite (or any BeforeX) not supporting labels. So we end up with all the initialization running, but only part of it is actually needed per the labels used.
It would be helpful if the BeforeSuite will support the labels: the same way as tests are skipped, we can skip some of the initialization too.
Is there a workaround for this?
The text was updated successfully, but these errors were encountered: