Test automation in Python. Six Ways to Test Effectively

We've already talked about test automation , now it's time to get to know the six best test automation tools in Python.





– Python . . Python , , .





Python, . 





, .





PyUnit Nose2

PyUnit – - Python. Python 2.1, . PyUnit – JUnit Python, - Java. , Java Python . Smalltalk .





PyUnit .





  • , , .





  • .





  • .





  • .





-:





import unittest
 
    class SimpleWidgetTestCase(unittest.TestCase):
        def setUp(self):
            self.widget = Widget("The widget")
 
    class DefaultWidgetSizeTestCase(SimpleWidgetTestCase):
        def runTest(self):
            assert self.widget.size() == (50,50), 'incorrect default size'
      
      



SimpleWidgetTestCase



setUp



, Widget



. DefaultWidgetSizeTestCase



– - SimpleWidgetTestCase



, Widget



.





PyUnit – Python, . . Nose.  





Nose2 – PyUnit. . Nose2 , . , AllModules





Nose2 Such – DSL .





test_widgets.py



, - Nose2 . , – tests_



.





PyTest

PyTest (https://pytest.org/en/latest/) – Python, PyUnit. JUnit, Python. Python.





PyTest ( Nose), .





Pytest , , .





@pytest.fixture
def widget():
    return Widget("The widget")
 
def test_widget_size(widget):
    assert widget.size() == (50,50), 'incorrect default size'
      
      



PyTest Widget .





, -, PyTest . , , , . PyTest . , PyUnit.





PyTest , XML HTML. PyTest.





, PyTest , -, PyUnit Nose2. PyTest , . PyTest Python 3.6 .





Behave

PyUnit PyTest – -, , behavior-driven ?





Behave – behavior-driven (BDD) . PyUnit PyTest. Gherkin Python. , Gherkin Cucumber, Behave Gherkin, BDD- Python.





Behave , Jetbrains PyCharm Professional Edition. - Behave.





, . , . Behave , .





behavior-driven (BDD), Behave – . Django, Flask, full-stack . 





Behave, . 





:





Feature: widget size
  Scenario: verify a widget's size
     Given we have a widget
     When the widget is valid
     Then the size is correct
      
      



Python. Given, When Then .





from behave import *

@given('we have a widget')
def step_given_a_widget(context):
    context.widget = Widget('The widget')   

@when('the widget is valid')
def step_widget_is_valid(context)
    assert context.widget is not None

@then('the size is correct')
def step_impl(context):
    assert context.widget.size() == (50,50)
      
      



Lettuce

Lettuce – behavior-driven Selenium Python. Behave, Gherkin , , Behave. Lettuce , Behave, .





, Selenium Nose





Lettuce - Behave. :





Feature: widget size 

Scenario: verify a widget's size 
    Given we have a widget 
    When the widget is valid 
    Then the size is correct
      
      



. , Lettuce step.





from lettuce import step
from lettuce import world 

@step('we have a widget') 
def step_given_a_widget(step):
    world.widget = Widget('The widget') 

@step('the widget is valid')
def step_widget_is_valid(step) 
    assert world.widget is not None 

@step('the size is corrrect') 
def step_impl(context): 
    assert world.widget.size() == (50,50)
      
      



Lettuce Selenium, Django. , Jasmine  JavaScript, .





Lettuce 2016 . , .





Jasmine Python

BDD – Python, -. Jasmine – - BDD. Jasmine, JavaScript, Python.





Jasmine-Py Jasmine Django. Jasmine Python CI/CD.





- , DOM, . , Django . Gherkin Jasmine





-, Django.





Robot

Robot – . . DSL Robot, , .





, , Jasmine, Robot .





– , . Robot, , . .





Robot , Python Java. , Python, Robot Python. Robot.





DSL . . , .





Python

Python . TIOBE. , Python .





Python , . , REST- , .





? Testim , . Python .






"Python QA Engineer". : , . .








All Articles