skip to navigation
skip to content

Not Logged In

describe_it 1.1.0

A nose plugin that supports writing describe/it style unit tests with nested contexts

Installing

$ pip install describe-it

Writing

Any module that ends with ‘spec’ is considered to contain specifications/tests for describe_it.

$ vim myfirst_spec.py

…and the content:

from game import Game
from describe_it import describe, it, before_each, Fixture

@describe           # This declares a test context.
def a_game():
    f = Fixture()   # Fixture is a hack to get around Python's
                    # implementation of closures. You can use
                    # other methods, such as nonlocal if you like.

    @before_each    # Will be called before each 'it' method.
    def setup():
        f.game = Game()

    @after_each     # Will be called after each 'it' method.
    def teardown():
        # This should rarely be needed!
        perform_post_test_cleanup_if_needed()

    @it             # This marks a test method.
    def is_player_ones_turn():
        # describe_it doesn't come with yet another assertion lib.
        # Pick any one you like.
        assert f.game.current_player == 1

    @describe   # This is a nested context that augments the context above.
    def in_second_round():

        # Before each 'it' method, any before_each in outer
        # contexts will be called first. Then this method
        # will be called.
        @before_each
        def setup():
            f.game.play_round()

        @it
        def is_player_twos_turn():
            assert f.game.current_player == 2

 # You can skip whole contexts by using '@xdescribe' or '@describe_skip'
 @xdescribe
 def this_context_is_marked_as_skipped():

    @it
    def this_test_will_be_skipped():
        assert True

 @describe
 def context_with_a_skipped_it_method():

    # You can skip individual test methods by using '@xit' or '@it_skip'
    @xit
    def this_test_will_be_skipped():
        assert True

    @it
    def this_test_will_be_run():
        assert True

Running

$ nosetests --with-describe-it
 
File Type Py Version Uploaded on Size
describe_it-1.1.0.tar.gz (md5) Source 2014-08-08 4KB
  • Downloads (All Versions):
  • 41 downloads in the last day
  • 193 downloads in the last week
  • 351 downloads in the last month
  • Author: Joakim Karlsson
  • Home Page: https://github.com/joakimkarlsson/describe_it
  • Keywords: unit testing,tdd,bdd,nose
  • License:
    The MIT License (MIT)
    
    Copyright (c) 2014 Joakim Karlsson
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
  • Package Index Owner: jhkarlsson
  • DOAP record: describe_it-1.1.0.xml