Is there a preferred BDD style unit testing framework for Python?

I was wondering if there are any BDD-style structural unit testing modules for Python that are supported and in production. I found describe , but it does not seem to be supported and has no documentation. I also found surewhich reached 1.0, but seems to just add syntactic sugar instead of writing statements. What I'm really looking for is similar to RSpec and Jasmine, which allows me to install test suites. A description syntax that allows you to test multiple instances of a function. Unlike the classical statement structure, which tests each function once and has several statements for testing several cases. This breaks the unit test isolation. If there is a way to achieve something like this with assertion-style testing, I would appreciate any advice on how to do this. The following are simple examples of both styles:

foo.py

class Foo():
    def bar(self, x):
        return x + 1

BDD-Style / Describe-It

test_foo.py

describe Foo:
    describe self.bar:
        before_each:
            f = Foo()

        it 'returns 1 more than its arguments value':
            expect f.bar(3) == 4

        it 'raises an error if no argument is passed in':
            expect f.bar() raiseError

UnitTest / Style Approval

test_foo.py

 class Foo():
     def test_bar(x):
         x = 3
         self.assertEqual(4)
         x = None
         self.assertRaises(Error)
+4
2

- rspec/capybara python, , . , python ( ). , python ruby.

, Cucumber (https://github.com/cucumber/cucumber/wiki/Python) (http://lettuce.it/), python.

+1

. , BDD Python, :

from mamba import describe, context, it
from expects import *

with describe("FrequentFlyer"):
    with context("when the frequent flyer account is first created"):
        with it("should initially have Bronze status"):
            frequentFlyer = FrequentFlyer()
            expect(frequentFlyer.status()).to(equal("BRONZE"))

Jasmine:

> pipenv run mamba --format=documentation frequent_flyer_test.py

FrequentFlyer
  when the frequent flyer account is first created
    ✓ it should initially have Bronze status

1 example ran in 0.0345 seconds
0

Source: https://habr.com/ru/post/1542863/


All Articles