Skip to content

[Feature request] Setup and teardown for tests #134171

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

Closed
Adrien-Bodineau opened this issue Dec 11, 2024 · 6 comments
Closed

[Feature request] Setup and teardown for tests #134171

Adrien-Bodineau opened this issue Dec 11, 2024 · 6 comments
Labels
A-libtest Area: `#[test]` / the `test` library C-feature-request Category: A feature request, i.e: not implemented / a PR. T-testing-devex Relevant to the testing devex team (testing DX), which will review and decide on the PR/issue.

Comments

@Adrien-Bodineau
Copy link

What about introducing new tests attributes for edition 2024 to allow global setup/teardown in tests ?

Something like

#[setup]
fn foo() {
    // do stuff...
}

#[teardown]
fn bar() {
    // undo stuff...
}

setup would run before all tests in its module and teardown after

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 11, 2024
@bjorn3
Copy link
Member

bjorn3 commented Dec 11, 2024

You might want to open an issue on https://github.com/rust-lang/libtest-next instead.

@GuillaumeGomez
Copy link
Member

Well, sounds like something that would definitely be useful to have without adding a dependency. I'd gladly use such a feature.

@bjorn3
Copy link
Member

bjorn3 commented Dec 11, 2024

libtest-next contains experiments for a rework of the existing testing support in rustc itself. I guess you could see the libtest-next issue tracker as a list of feature requests for whatever the new implementation of testing support for rust will end up.

@jieyouxu jieyouxu added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-testing-devex Relevant to the testing devex team (testing DX), which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 11, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 11, 2024

AFAIK libtest itself is more or less feature-frozen at the moment, and it is extremely unlikely to accept new feature requests. I see you have already filed rust-lang/libtest-next#79.

I'm going to leave this open for T-testing-devex to decide, but I think it might be closed in favor of libtest-next's issue tracker instead.

@jieyouxu jieyouxu added the A-libtest Area: `#[test]` / the `test` library label Dec 11, 2024
@jieyouxu
Copy link
Member

Actually, this feature request is a duplicate of #117668. I'm going to close this in favor of the earlier request. Thank you for the request.

@GuillaumeGomez
Copy link
Member

Oh I see. Didn't know test was in rework. It's great news!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: `#[test]` / the `test` library C-feature-request Category: A feature request, i.e: not implemented / a PR. T-testing-devex Relevant to the testing devex team (testing DX), which will review and decide on the PR/issue.
Projects
Development

No branches or pull requests

5 participants