Skip to content

[Feature request] Setup and teardown for tests #79

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

Open
Adrien-Bodineau opened this issue Dec 11, 2024 · 1 comment
Open

[Feature request] Setup and teardown for tests #79

Adrien-Bodineau opened this issue Dec 11, 2024 · 1 comment

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

@epage
Copy link
Contributor

epage commented Dec 11, 2024

FYI this is also being discussed at rust-lang/rust#117668.

Quoting myself from over there:

FYI this is owned by libtest which is in the rust repo, and not cargo. We've also recently formed a testing-devex team to focus on improving the workflows around tests in a cross-team way.

As this is a fairly fundamental change, I would recommend experimenting in a library first for these ideas (pytest-rs is where my experiments live) and then bringing that proposal forward on internals.

However, this is unlikely to happen, directly. Last I talked to the libs team, we walked away with the idea that we'd work to make harness=false harnesses first class citizens and focus on feature development there, rather than in libtest. pytest-rs is my experiment towards that goal.

For myself, I see setup and teardown to be redundant with fixture and anti-patterns as they tend towards "god fixtuures" that encompass too much and slow down tests. The proposal given also doesn't provide a way to pass state from setup to the test to teardown and doesn't cover process-wide vs test-wide setup/teardown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants