Skip to main content

for "Behavior Driven Development" (BDD) -- a client-facing scripting language to put the squeeze on all your features

Project description

Wheel Status Python versions Latest Version License Build status Coverage Documentation Updates https://img.shields.io/badge/code%20style-black-000000.svg

Morelia is a Python Behavior Driven Development (BDD) library.

BDD is an agile software development process that encourages collaboration between developers, QA and business participants.

Test scenarios written in natural language make BDD foundation. They are comprehensible for non-technical participants who wrote them and unambiguous for developers and QA.

Morelia makes it easy for developers to integrate BDD into their existing unittest frameworks. It is easy to run under nose, pytest, tox, trial or integrate with django, flask or any other python framework because no special code have to be written.

You as developer are in charge of how tests are organized. No need to fit into rigid rules forced by some other BDD frameworks.

Mascot:

http://www.naturfoto.cz/fotografie/ostatni/krajta-zelena-47784.jpg

Installation

pip install morelia

Quick usage guide

Write a feature description:

# calculator.feature

Feature: Addition
    In order to avoid silly mistakes
    As a math idiot
    I want to be told the sum of two numbers

Scenario: Add two numbers
    Given I have powered calculator on
    When I enter "50" into the calculator
    And I enter "70" into the calculator
    And I press add
    Then the result should be "120" on the screen

Create standard Python’s unittest and hook Morelia into it:

# test_acceptance.py

import unittest

from morelia import verify


class CalculatorTestCase(unittest.TestCase):

    def test_addition(self):
        """ Addition feature """
        verify('calculator.feature', self)

Run test with your favourite runner: unittest, nose, py.test, trial. You name it!

$ python -m unittest -v test_acceptance  # or
$ pytest test_acceptance.py  # or
$ nosetests -v test_acceptance.py  # or
$ trial test_acceptance.py  # or
$ # django/pyramid/flask/(place for your favourite test runner)

And you’ll see which steps are missing:

F
======================================================================
FAIL: test_addition (test_acceptance.CalculatorTestCase)
Addition feature.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "(..)test_acceptance.py", line 31, in test_addition
    verify(filename, self)
  File "(..)/morelia/__init__.py", line 120, in verify
    execute_script(feature, suite, scenario=scenario, config=conf)
  File "(..)/morelia/parser.py", line 59, in execute_script
    assert not_found == set(), message
AssertionError: Cannot match steps:

    def step_I_have_powered_calculator_on(self):
        r'I have powered calculator on'

        raise NotImplementedError('I have powered calculator on')

    def step_I_enter_number_into_the_calculator(self, number):
        r'I enter "([^"]+)" into the calculator'

        raise NotImplementedError('I enter "50" into the calculator')

    def step_I_enter_number_into_the_calculator(self, number):
        r'I enter "([^"]+)" into the calculator'

        raise NotImplementedError('I enter "70" into the calculator')

    def step_I_press_add(self):
        r'I press add'

        raise NotImplementedError('I press add')

    def step_the_result_should_be_number_on_the_screen(self, number):
        r'the result should be "([^"]+)" on the screen'

        raise NotImplementedError('the result should be "120" on the screen')

----------------------------------------------------------------------
Ran 1 test in 0.013s

FAILED (failures=1)

Now implement steps with standard TestCases that you are familiar:

# test_acceptance.py

import unittest

from morelia import verify


class CalculatorTestCase(unittest.TestCase):

    def test_addition(self):
        """ Addition feature """
        verify('calculator.feature', self)

    def step_I_have_powered_calculator_on(self):
        r'I have powered calculator on'
        self.stack = []

    def step_I_enter_a_number_into_the_calculator(self, number):
        r'I enter "(\d+)" into the calculator'  # match by regexp
        self.stack.append(int(number))

    def step_I_press_add(self):  # matched by method name
        self.result = sum(self.stack)

    def step_the_result_should_be_on_the_screen(self, number):
        r'the result should be "{number}" on the screen'  # match by format-like string
        self.assertEqual(int(number), self.result)

And run it again:

$ python -m unittest test_acceptance

Feature: Addition
    In order to avoid silly mistakes
    As a math idiot
    I want to be told the sum of two numbers
Scenario: Add two numbers
    Given I have powered calculator on                       # pass  0.000s
    When I enter "50" into the calculator                    # pass  0.000s
    And I enter "70" into the calculator                     # pass  0.000s
    And I press add                                          # pass  0.001s
    Then the result should be "120" on the screen            # pass  0.001s
.
----------------------------------------------------------------------
Ran 1 test in 0.028s

OK

Note that Morelia does not waste anyone’s time inventing a new testing back-end just to add a layer of literacy over our testage. Steps are miniature TestCases. Your onsite customer need never know, and your unit tests and customer tests can share their support methods. The same one test button can run all TDD and BDD tests.

Look at example directory for a little more enhanced example and read full documentation for more advanced topics.

Documentation

Full documentation is available at http://morelia.readthedocs.org/en/latest/index.html

http://zeroplayer.com/images/stuff/sneakySnake.jpg

Credits

This package was created with Cookiecutter and the kidosoft/cookiecutter-pypackage project template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

morelia-0.9.1.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

morelia-0.9.1-py3-none-any.whl (30.9 kB view details)

Uploaded Python 3

File details

Details for the file morelia-0.9.1.tar.gz.

File metadata

  • Download URL: morelia-0.9.1.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.16 CPython/3.7.3 Linux/5.1.8-arch1-1-ARCH

File hashes

Hashes for morelia-0.9.1.tar.gz
Algorithm Hash digest
SHA256 2cd7c7b1f6e783fc66a03dd589e898f4c7402a2c7e156303c1f5cecf507b71a4
MD5 7a97b6a51d06052da5690f42a5f9ab9a
BLAKE2b-256 6ef041c861fa35fdc6a6f812e881a1f0920be5b463d926cf24de846c7f72bebe

See more details on using hashes here.

File details

Details for the file morelia-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: morelia-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 30.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.16 CPython/3.7.3 Linux/5.1.8-arch1-1-ARCH

File hashes

Hashes for morelia-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12cae0fb05785cab8991fcbeecc106d3213fd25e1a26706138cc3f3f1aefe011
MD5 e4ab1121874ffc4bbd291fc5459081c7
BLAKE2b-256 faaa3606c145c133b168c54ef74bf128af4c6745eb45976e4b5a7ba73bf5b75d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page