Feature request: Ability to run tests from main thread #1959
Replies: 6 comments 16 replies
-
Hi — thanks for the issue! I agree this is unfortunate, when first building nextest I thought that if you run a single test, libtest wouldn't create a thread for it even if --test-threads=1 isn't specified. If I were building nextest from scratch today, I'd definitely always pass in --test-threads=1. But I'm worried about backwards compatibility if we just change the default here, for two reasons: custom test harnesses which may not support --test-threads, and tests that depend on being run in another thread. I think what we can do is make this an option to opt into, though. I'm torn between a purpose-built option for this and a general "pass these additional arguments into the test binary while running tests" option. What do you think? |
Beta Was this translation helpful? Give feedback.
-
Hello @sunshowers! Thank you for your response. Yeah, I totally understand the backwards compatibility issue. I'd keep Could you please describe the options you are describing in more details?
Is this what happens when I run just normal |
Beta Was this translation helpful? Give feedback.
-
[profile.default]
run-on-main-thread = true This looks great to me. I think it's more like a project configuration rather than an argument for a particular run. Because it can be critical for the tests to succeed. Without them running in the main thread they just fail and it would be a false negative. |
Beta Was this translation helpful? Give feedback.
-
Hmm, so I have the option working, but it looks like it won't help with newer versions of Rust, which always create a thread to run the test in, even if (My memory of this was from back in 2022 when nextest first came out, and was outdated for that reason :) ) Nextest just delegates to libtest here, so I don't think nextest can do anything special unfortunately. You may be able to use a custom test harness to achieve this. |
Beta Was this translation helpful? Give feedback.
-
@sunshowers I've tried |
Beta Was this translation helpful? Give feedback.
-
Going to close this discussion since the need has been addressed via https://nexte.st/docs/configuration/extra-args/. Thanks for the report! |
Beta Was this translation helpful? Give feedback.
-
Motivation
I'm the developer of osakit crate. That crate provides an API to work with OSAKit Framework from MacOS.
The problem is that OSAKit only works properly when executed from the main thread.
nextest
runs tests from a separate thread even if--test-threads
is set to1
. This makes OSAKit tests fail.The same problem also applies basically to any
rust
application which uses MacOS UI Frameworks, because they also require main thread.Proposal
I suggest adding a CLI option which will make nextest run tests in the main thread only.
Alternatives
This question was asked for
cargo test
before:Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions