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

"check" convenience shortcut for subtests fixture #28

Closed
wants to merge 1 commit into from

Commits on Jun 18, 2020

  1. "check" convenience shortcut for subtests fixture

    - Support nested `subtests.test()` contexts similar to
      `unittest.TestCase.subTest()` chaining of argument sets.
    - Make `subtests` instance a re-entrable context manager
      similar to `subtests.test()`.
    - Make `subtests` instance a callable that sets context (scope)
      for further subtests or for nested scopes only if return
      value is used as a context manager.
    - Add `check` concise alias for the `subtests` fixture.
    
    Essentially, the goal is to adapt `pytest-subtests` for checking
    of multiple aspects of compound objects, e.g. a class fields, withing a
    single unit test and to get report with all failures at once instead of
    the first error only.
    
        from datetime import datetime
    
        def test_fields(check):
            dt = datetime.utcfromtimestamp(1234567890)
            with check: assert dt.year == 2009, "Year is OK"
            with check: assert dt.month == 1
            with check: assert dt.day == 13, "Day is OK"
            with check: assert dt.hour == 27
    
    Use with `--tb=short` option.
    
    The bright idea of context manager shortcut belongs to @ionelmc:
    okken/pytest-check#9
    maxnikulin committed Jun 18, 2020
    Configuration menu
    Copy the full SHA
    fd9dcae View commit details
    Browse the repository at this point in the history