Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upNeed way to run some code before any of unit tests #35762
Comments
Dushistov
referenced this issue
Aug 17, 2016
Closed
Need way to run some code before any of unit tests #3008
This comment has been minimized.
This comment has been minimized.
|
You can call |
This comment has been minimized.
This comment has been minimized.
|
Another workaround is to put the initialization code in a lazy static, and make sure to access said static at the beginning of every test (a macro can help). Then it will really only run once. |
This comment has been minimized.
This comment has been minimized.
|
@durka If you're going to do that, you might as well just use |
This comment has been minimized.
This comment has been minimized.
|
A similar, and even more difficult issue, is if you want to run teardown after all the tests have run. |
Mark-Simulacrum
added
the
T-libs
label
May 20, 2017
Mark-Simulacrum
added
A-libtest
C-feature-request
labels
Jul 25, 2017
This comment has been minimized.
This comment has been minimized.
|
I agree that setup and teardown for tests would be useful. This is going to need an RFC so let's track it under rust-lang/rfcs#1664. |
Dushistov commentedAug 17, 2016
The details can be found logging while running cargo test.
The problem is in usage of rust log library,
to get it work you need call "initialization" code that provide implementation of
log::Logtraitto logging macros.
So to get output from your code that tested by "cargo test" you need somehow call "logging_init" function, but as can I see at now there is no way to tell "cargo" run something before any tests.
Previously reported as cargo bug