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

Rework fixtures #50

Merged
merged 16 commits into from
Aug 24, 2018
Merged

Rework fixtures #50

merged 16 commits into from
Aug 24, 2018

Commits on Jul 25, 2018

  1. Rework fixtures

    - Add @pytest_trio.trio_fixture for explicitly marking a fixture as
      being a trio fixture
    - Make the nursery fixture a @trio_fixture
    - Refactor Trio fixture classes into one class
    - Check for trio marker instead of trio keyword (fixes python-triogh-43)
      - This also raises the minimum pytest version to 3.6
    - Raise an error if a Trio fixture is used with a non-function
      scope (fixes python-triogh-18)
    - Raise an error if a Trio fixture is used with a non-Trio test
    
    I think this also closes python-triogh-10's discussion, though we still need to
    convince pytest-asyncio to fix their side of things.
    njsmith committed Jul 25, 2018
    Configuration menu
    Copy the full SHA
    2036d76 View commit details
    Browse the repository at this point in the history
  2. Rename 'nursery' fixture to 'test_nursery'

    Every nursery is called 'nursery'. This is less generic, and
    emphasizes that this nursery is special, because its lifetime is
    linked to the test.
    
    Kept 'nursery' around for now as a deprecated alias.
    njsmith committed Jul 25, 2018
    Configuration menu
    Copy the full SHA
    82afdab View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    87fd141 View commit details
    Browse the repository at this point in the history
  4. In Trio mode, auto-convert async fixtures to Trio fixtures

    The main benefit of this is that it lets us catch more cases where
    these fixtures are accidentally misused.
    
    Closes python-triogh-18
    Closes python-triogh-51
    njsmith committed Jul 25, 2018
    Configuration menu
    Copy the full SHA
    eb42b8a View commit details
    Browse the repository at this point in the history

Commits on Aug 15, 2018

  1. Totally redo fixture/test setup/teardown, yet again

    See python-trio#55 for discussion.
    
    Main points:
    
    * Fixture setup/teardown is now performed concurrently whenever
      possible.
    
    * Each fixture is now run in an isolated task, and it's now safe to
      use nurseries inside fixtures (fixes python-triogh-55).
    
    * New magical fixture 'fixture_nursery' which gives a nursery that's
      cancelled immediately after *the requesting fixture finishes
      teardown*. If requested directly by the test itself, gives a nursery
      which is cancelled after the test finishes, before other fixtures
      are torn down.
    njsmith committed Aug 15, 2018
    Configuration menu
    Copy the full SHA
    fe65b49 View commit details
    Browse the repository at this point in the history
  2. Remove stray prints

    njsmith committed Aug 15, 2018
    Configuration menu
    Copy the full SHA
    4a477a5 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    4f8a019 View commit details
    Browse the repository at this point in the history
  4. yapf

    njsmith committed Aug 15, 2018
    Configuration menu
    Copy the full SHA
    4e31ce9 View commit details
    Browse the repository at this point in the history
  5. Revert back to 'nursery' as the name of the magic nursery fixture

    At this point this:
    
    @pytest.fixture
    async fix(nursery):
        ...
    
    is just a shorthand for this (they should be exactly equivalent):
    
    @pytest.fixture
    async fix():
        async with trio.open_nursery() as nursery:
            try:
                ...
            finally:
                nursery.cancel_scope.cancel()
    
    And the latter is the obvious thing you would write by hand, there's
    really no other way to do it. And since it no longer has special
    subtle semantics, I'm no longer bothered by using the short name
    'nursery'. Plus the longer I looked at 'fixture_nursery' the more
    annoying the name seemed. Plus I made that last minute change so you
    can use the magic nursery inside tests too, not just fixtures, so the
    name didn't even make much sense.
    njsmith committed Aug 15, 2018
    Configuration menu
    Copy the full SHA
    25e9e19 View commit details
    Browse the repository at this point in the history

Commits on Aug 17, 2018

  1. Configuration menu
    Copy the full SHA
    0154411 View commit details
    Browse the repository at this point in the history
  2. yapf

    njsmith committed Aug 17, 2018
    Configuration menu
    Copy the full SHA
    9138b86 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    4d2ec80 View commit details
    Browse the repository at this point in the history

Commits on Aug 22, 2018

  1. Share contextvars across fixtures

    This is sort of a gross hack, but it's simple and works. If it causes
    problems, then this comment discusses some other options:
      python-trio#50 (comment)
    
    Also added tests for using trio-asyncio in fixtures (which was the
    motivating use case for sharing contextvars).
    njsmith committed Aug 22, 2018
    Configuration menu
    Copy the full SHA
    ef0cd26 View commit details
    Browse the repository at this point in the history
  2. py35 compatibility

    njsmith committed Aug 22, 2018
    Configuration menu
    Copy the full SHA
    2e5f6f7 View commit details
    Browse the repository at this point in the history
  3. Skip trio-asyncio tests on py35

    When importing trio-asyncio v0.8.0 on py35, we get a crash at import
    time:
    
      .../python3.5/site-packages/trio_asyncio/loop.py:171: in <module>
          _orig_run_get = _aio_event._get_running_loop
      E   AttributeError: module 'asyncio.events' has no attribute '_get_running_loop'
    
    See: https://travis-ci.org/python-trio/pytest-trio/jobs/419092404
    
    So let's skip testing this for now...
    njsmith committed Aug 22, 2018
    Configuration menu
    Copy the full SHA
    b0559c1 View commit details
    Browse the repository at this point in the history
  4. THIS TIME FOR SURE

    njsmith committed Aug 22, 2018
    Configuration menu
    Copy the full SHA
    98ba48b View commit details
    Browse the repository at this point in the history