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

Collection contexts #76

Open
stony8 opened this issue Feb 5, 2011 · 3 comments
Open

Collection contexts #76

stony8 opened this issue Feb 5, 2011 · 3 comments
Milestone

Comments

@stony8
Copy link

stony8 commented Feb 5, 2011

In attest, tests may have contexts. What about contexts for test
collections
? They would be useful for expensive setup/teardown of a
collection's "environment".

I know that they would not be trivial to add since, currently, Tests.register()
merges/"flattens" in tests of a "sub-collection".

Have collection contexts been considered? If yes, have they been left out as a
feature decision/for simplicity?

@dag
Copy link
Owner

dag commented Feb 5, 2011

Mainly left out so far because:

  • I'd like test functions to work correctly if called directly
  • Proper testing should ensure isolation I think

But the latter is not a strong enough reason for me to leave it out; if you know what you're doing, collection-wide contexts can be useful as you say. The former is more tricky, as you also noted. Would be easy to make it work per function, just treat collection contexts as test contexts, but for running a whole collection something different would need to happen.

I think it might be somewhat trivial to add shared contexts for everything in a collection but I think it should not be for "sub-collections". A collection would need to be defined with more assumptions than "iterable yielding tests".

@dag
Copy link
Owner

dag commented Apr 18, 2011

Maybe we could have 'shared contexts' that keep track of the tests they surround, and only runs the setup the first time we 'enter', and the teardown when all tracked tests have 'exited'. Unless I'm confused, I think that could work while keeping tests-as-simple-callables and collections-as-simple-iterables.

@dag
Copy link
Owner

dag commented Apr 18, 2011

…except it wont work for running individual tests by calling, if not all tests in the collection are run. The teardown would never run. Exit handlers could be used to ensure teardown is handled before the process exits, which will not work optimally if the process is kept alive.

Running individual tests and keeping processes alive are probably rare uses, so it's probably "good enough", with the gotcha's documented. Some way to trigger all teardown could also be added, maybe with some use of signals and a context manager for enclosing a run of arbitrary tests.

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

No branches or pull requests

2 participants