Skip to content
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

[feature request] Ability to define suite-level fixtures #19

Open
pmolodo opened this issue Feb 13, 2020 · 4 comments
Open

[feature request] Ability to define suite-level fixtures #19

pmolodo opened this issue Feb 13, 2020 · 4 comments

Comments

@pmolodo
Copy link

pmolodo commented Feb 13, 2020

I'd love the ability to define fixtures that are set up + torn down once for the entire test suite. This would be similar to setting the scope of a fixture to "class" for pytest fixtures (since you seem familiar with pytest).

@mindsbackyard
Copy link
Owner

mindsbackyard commented Feb 23, 2020

Thanks for your input! Yes that's a feature which would come in handy if setup/tear-down costs are high. On the other hand you might risk leaking state from one test to another which wouldn't be that nice.

There's also the issue with the ownership model of Rust which imposes some restrictions on the shared fixture, e.g., as the fixture data would be used by multiple tests a fixture might only immutable references to the data either in the form of an immutable borrow, an Rc, or an Arc. Further as Rust allows you to run tests in parallel (galvanic-test hinders parallelism a bit atm---which should change) the returned data should also be thread-safe (so no Rcs).

Could you please elaborate what you want to achieve? Would sharing immutable data be enough? Would you like to use the same fixture in multiple suites (set up and torn down separately for each of them)?

@pmolodo
Copy link
Author

pmolodo commented Feb 24, 2020

In my particular use case I just wanted to do some filesystem setup - create some directories and some read-only relative filepaths. These files could be shared between tests.

So in my case, I think the only data I would need would be the name of the paths created - so an immutable reference would be fine.

@pmolodo
Copy link
Author

pmolodo commented Feb 24, 2020

As for behavior in multiple suites - in my use case, I think either would be fine (ie, it's setup and torn down for each suite, or it's setup for the first suite that uses, and torn down for the last suite), though I suppose the latter behavior would effective make it a session-level fixture, not a suite-level one. So I suppose all I'm saying is that for me, either session or suite fixtures would be ok. I think suite would probably be more broadly useful, though.

@Mastermindaxe
Copy link

So more or less a before_all and before_each fixture right? I'd love to see a test library actually implement this. Maybe the data you share should implement Send + Sync? I'd be fine with some restrictions on this feature, but it looks like a feature that should be there tbh.

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

3 participants