-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow crate to attach uniform initialization behavior to every #[test]
#1664
Comments
(as a quick counterpoint: this is relatively low priority, since when one is debugging the behavior on a particular test, it is usually a very small cost to add the single line of |
People ask all the time for setup and teardown facilities in the test harness. You can hack it in with a macro but it's not the best and doesn't work for doctests as you said. |
Just coming to chime in on the utility of this. I'm working on two projects, one of which uses a database I'd like to be able to set up and tear down without manually running commands, and the other I just committed about 25 times to solve an issue that occurred only in my CI. If I could have initialized logging that would have been solved. |
In servo/servo#21884 I’ve exploited a loophole in how I’m aware of rust-lang/rust#50297, but besides it not being implemented I’d prefer to have to write an entire test harness. I like CC @rust-lang/libs |
This issue’s title says “to every |
Really, the two are related but not identical problems. For my use case, I actually need both.
|
(You’re probably aware of this, but in that case you might need to force tests to run on a single thread as that’s not the default. Otherwise a test test might still be running at the time another finishes.) |
Yes, that's necessary but unfortunately insufficient. My current solution is build the test environment, get the data I want to check, perform cleanup, and then |
@SimonSapin nowadays I think it's also a viable option to have something like: #[my_test_macro]
fn my_test(with: &MyArgs, and: &GlobalResourceInitializedOnce) {
// ...
} Would that work for Servo? |
This is still an issue. I agree with what @alexcrichton suggested but slightly different use might be better. #[my_test_macro]
fn my_test(with: &MyArgs, and: &Box<dyn BeforeAndAfterAll>) {
// ...
} Where multiple traits make sense like BeforeAndAfterEach etc. so a trait method might be used later for scheduling the callbacks. |
This would be ideal for my use case. setup()
test1()
test2()
test3()
teardown() This would allow all tests to be run in parallel instead of having to run with Is this still being considered under this RFC? |
That's more likely covered by https://rust-lang.github.io/rfcs/2318-custom-test-frameworks.html |
Back when support for logging macros like
debug!
and what not was more heavily baked into the language and stdlib, I think we were able to see output from such logging macros from the#[test]
unit tests.But now, one cannot, at least not without adding explicit code to initialize the logging subsystem to every unit tests.
See also this StackOverflow Q here: http://stackoverflow.com/questions/30177845/how-to-initialize-the-logger-for-integration-tests
It is a shame that we offer both of these features (integrated unit tests and a logging subsystem), and yet they do not compose as seamlessly as one might hope.
The text was updated successfully, but these errors were encountered: