Is there a python equivalent for RSpec to do TDD?

放肆的年华 提交于 2019-12-02 17:41:00
Torben Knerr

The closest I have come to doing a brief google search was mamba + expects:

I love Rspec! On python, I am going to use a py.test plugin called spec: https://pypi.python.org/pypi/pytest-spec https://github.com/pchomik/pytest-spec

It uses unittest, the default python package, plus pytest and itself. Upon cloning the project to my python 2.7 conda OSX 10.11 installation, I was able to run its own tests, and it worked fine!

The format is simple, but it includes the basics: a group name, the pass/fail/skip status, and the name of the test spelled out with spaces instead of underscores. Here's some output from their own tests, which seem simple for me to follow on my own.

    $ py.test --spec
================================ test session starts =================================
platform darwin -- Python 2.7.11, pytest-2.9.2, py-1.4.31, pluggy-0.3.1
rootdir: /Users/ME/src/pytestspec, inifile: setup.cfg
plugins: spec-1.0.1, testinfra-1.4.1
collected 30 items 

test/test_patch.py::TestPatch
    [PASS]  Pytest runtest logreport honors capitalization of words in test name
    [PASS]  Pytest runtest logreport marks method marked by double underscores
    [PASS]  Pytest runtest logreport prints class name before first test result
    [PASS]  Pytest runtest logreport prints test name and failed status
    [PASS]  Pytest runtest logreport prints test name and handle only single marker
    [PASS]  Pytest runtest logreport prints test name and passed status
    [PASS]  Pytest runtest logreport prints test name and skipped status
    [PASS]  Pytest runtest logreport returns none when letter is missing
    [PASS]  Pytest runtest logreport returns none when nodeid is wrong formatted
    [PASS]  Pytest runtest logreport returns none when word is missing
    [PASS]  Pytest runtest logreport skips empty line for first test
    [PASS]  Pytest runtest logstart returns none

test/test_plugin.py::TestPlugin
    [PASS]  Pytest adoption adds spec option
    [PASS]  Pytest adoption gets general group
    [PASS]  Pytest configure reloads pytest after patching
    [PASS]  Pytest configure should not reload configuration

test/test_replacer.py::TestPatcher
    [PASS]  Logstart replacer returns result of pytest runtest logstart method
    [PASS]  Report replacer returns result of pytest runtest logreport method

test/test_formats/test_functions.py
    [PASS]  Some function returns none
    [PASS]  Some function single underscore as prefix
    [PASS]  Some function single underscore as suffix

test/test_formats/test_methods.py::TestFormats
    [PASS]  Some method returns none
    [PASS]  Some method single underscore as suffix
    [PASS]  Some method single underscore as prefix

test/test_results/test_as_class.py::TestResults
    [SKIP]  Some method return none
    [SKIP]  Some method returns false
    [PASS]  Some method returns true

test/test_results/test_as_functions.py
    [PASS]  Some method returns true
    [SKIP]  Some method returns false
    [SKIP]  Some method return none

======================== 26 passed, 4 skipped in 0.14 seconds ========================

http://pythonhosted.org/behave/

This is one solution to behavior driven development in python. Might help.

There is also https://testinfra.readthedocs.io/en/latest/ if you can use servespec which according to the website says

Testinfra aims to be a Serverspec equivalent in python and is written as a plugin to the powerful Pytest test engine

I'd much rather be doing python but I'm having to deal with ruby. C'est La Vie.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!