-
Notifications
You must be signed in to change notification settings - Fork 11
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
Ignore variables in test packages/files #11
Comments
That can cause side effects to leak from one test to the next though. Could you share an example of when a global variable is required for tests instead of a function that returns a setup to be shared across tests? |
Facing the same issue here. My setup is expensive to prepare (loading a BPF program into the kernel). I want to perform this setup step only once and then reuse it across several tests. So I basically get a file descriptor in TestMain that I want to share with my test cases. |
|
Thanks for the suggestion leon, I didn't know about this flag. I am actually using |
A bit late to the party but |
It's also worth noting |
I think the two recommendations above not using the |
I'm a bit late to this party, but I'm using the "golden files" pattern ( https://speakerdeck.com/mitchellh/advanced-testing-with-go?slide=19 ) for my tests (see my actual code here). I really want to add
Any ideas? And thanks for this tool, I love this idea! |
@bbkane There's a couple options I'm aware of. Others might chime in with additional ideas. Here's what I know: You can use Another option is to put that |
That seems to work, thank you! //nolint:gochecknoglobals // https://github.com/leighmcculloch/gochecknoglobals/issues/11#issuecomment-1368578131
var update = stdlibflag.Bool("update", false, "update golden files") Although if you (or anyone) hear about any techniques to write an |
It is possible to initialize test variables by
TestMain
. However global variables are the only way to share data withTestMain
and tests. Can we ignore global variables in_test
packages or_test.go
files in general?The text was updated successfully, but these errors were encountered: