All Projects → mdwhatcott → Pyspecs

mdwhatcott / Pyspecs

Licence: other
Minimalistic BDD in Python

Programming Languages

python
139335 projects - #7 most used programming language
python2
120 projects

Projects that are alternatives of or similar to Pyspecs

Pict
Pairwise Independent Combinatorial Tool
Stars: ✭ 681 (+1602.5%)
Mutual labels:  testing-tools
Wufei
Async Kuberenetes Namespace Log Recorder / Streamer
Stars: ✭ 27 (-32.5%)
Mutual labels:  testing-tools
Mts
Project of Multi-protocol Test Tool opensourced by Ericsson
Stars: ✭ 34 (-15%)
Mutual labels:  testing-tools
Mixer
Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.
Stars: ✭ 743 (+1757.5%)
Mutual labels:  testing-tools
Pytest Ui
Text User Interface for running python tests
Stars: ✭ 23 (-42.5%)
Mutual labels:  testing-tools
Chn Eolinker Ams Lite 4.0 For Php
中国最大的在线API管理平台EOLINKER 旗下API管理系统开源精简版,适合个人以及微型团队使用。
Stars: ✭ 869 (+2072.5%)
Mutual labels:  testing-tools
Faker
Faker is a pure Elixir library for generating fake data.
Stars: ✭ 673 (+1582.5%)
Mutual labels:  testing-tools
Junit Extensions
JUnit5 extensions library including JUnit5 equivalents of some of the common JUnit4 rules: ExpectedException, TemporaryFolder etc
Stars: ✭ 39 (-2.5%)
Mutual labels:  testing-tools
Funceble
[ARCHIVED] Please report to https://github.com/funilrys/PyFunceble.
Stars: ✭ 25 (-37.5%)
Mutual labels:  testing-tools
Pyats Docker
Dockerfile and scripts for pyATS
Stars: ✭ 34 (-15%)
Mutual labels:  testing-tools
Avoriaz
🔬 a Vue.js testing utility library
Stars: ✭ 771 (+1827.5%)
Mutual labels:  testing-tools
Flaui
UI automation library for .Net
Stars: ✭ 892 (+2130%)
Mutual labels:  testing-tools
Hoppscotch
👽 Open source API development ecosystem https://hoppscotch.io
Stars: ✭ 34,569 (+86322.5%)
Mutual labels:  testing-tools
Cuprite
Headless Chrome/Chromium driver for Capybara
Stars: ✭ 743 (+1757.5%)
Mutual labels:  testing-tools
Rxschedulerrule
Simple JUnit rule for overriding RxJava/RxAndroid schedulers during unit tests
Stars: ✭ 35 (-12.5%)
Mutual labels:  testing-tools
Firebase Server
Firebase Realtime Database Server Implementation
Stars: ✭ 673 (+1582.5%)
Mutual labels:  testing-tools
Structured Acceptance Test
An open format definition for static analysis tools
Stars: ✭ 10 (-75%)
Mutual labels:  testing-tools
Websocket Connection Smuggler
websocket-connection-smuggler
Stars: ✭ 40 (+0%)
Mutual labels:  testing-tools
Webmockr
R library for stubbing and setting expectations on HTTP requests
Stars: ✭ 37 (-7.5%)
Mutual labels:  testing-tools
Cypress
Fast, easy and reliable testing for anything that runs in a browser.
Stars: ✭ 35,145 (+87762.5%)
Mutual labels:  testing-tools

pyspecs - Minimalistic BDD in Python

Build Status

pyspecs is a testing framework that strives to achieve more readable specifications (tests) by leveraging some fancy syntactic sugar and auto-discovery of tests/specs. WARNING: version 2.0 introduces breaking changes if you've been using 1.0 or 1.1.

Installation is straightforward:

$ pip install pyspecs

or...

$ easy_install pyspecs

or...

$ git clone https://[email protected]/mdwhatcott/pyspecs.git
$ cd pyspecs
$ python setup.py

Assertions

The main tool for verifying behavior is an assertion of some kind. The simplest assertion can be made by using the built-in assert statement:

assert 42 == 'The answer the life, the universe and everything'

For readability this project provides a more fluent method for making assertions:

# These imported names are all synonyms for the class that
# provides fluent assertions (Should). Use whichever provides
# the best readability.  The general patter is:
# >>> the([value]).should.[condition_method]([comparison_args])
#  or...
# >>> the([value]).should_NOT.[condition_method]([comparison_args]) # negated!

from pyspecs import the, this, that, it


this(42).should.equal(42) # this passes

this([1, 2, 3]).should.contain(2) # this also passes

the(list()).should.be_empty() # passes

it(1).should_NOT.be_greater_than(100) # passes

# raises AssertionError, caught by framework, logged as failure
that(200).should.be_less_than(0)

Writing complete specs

from pyspecs import given, when, then, and_, the


with given.two_operands:
    a = 2
    b = 3

    with when.supplied_to_the_add_function:
        total = a + b

        with then.the_total_should_be_mathmatically_correct:
            the(total).should.equal(5)

        with and_.the_total_should_be_greater_than_either_operand:
            the(total).should.be_greater_than(a)
            the(total).should.be_greater_than(b)

    with when.supplied_to_the_subtract_function:
        difference = b - a

        with then.the_difference_should_be_mathmatically_correct:
            the(difference).should.equal(1)

    # cleanup is just based on scope
    del a, b, total, difference

Notice that the names of each step are supplied as dynamic attributes of the given, when, then, and and_ step keywords. These user-created attributes are used in the output (below). Here is a listing of words that can be used as steps:

  • given
  • provided
  • when
  • then
  • and_
  • so
  • therefore
  • however
  • as_well_as

These steps can be arranged in any order and hierarchy for compose a specification (spec). You can even create your own steps that suit your needs (see the source code for how that's done).

Execution of specs

Beyond providing the python library which will be explained below, installation provides a command-line script into the environment, meant to be invoked from the root of your project. The script will execute all specs in .py files ending in 'test.py' or 'tests.py' or beginning with 'test'.

To run all tests once:

$ run_pyspecs.py

To begin an auto-test loop (runs all specs anytime a .py file is saved):

$ run_pyspecs.py -w

Complete Example

There are some complete examples of specs, code, and output in the examples folder.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].