Is there a python equivalent for RSpec to do TDD?

前端 未结 4 544
感动是毒
感动是毒 2021-01-30 09:00

I\'m looking for a test framework like Ruby\'s RSpec to do test driven development in Python. The advantage of a framework like RSpec is that it offers a DSL that lends itself w

相关标签:
4条回答
  • 2021-01-30 09:42

    http://pythonhosted.org/behave/

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

    0 讨论(0)
  • 2021-01-30 09:44

    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.

    0 讨论(0)
  • 2021-01-30 09:46

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

    • mamba: https://github.com/nestorsalceda/mamba
    • expects: https://github.com/jaimegildesagredo/expects
    0 讨论(0)
  • 2021-01-30 09:48

    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 ========================
    
    0 讨论(0)
提交回复
热议问题