Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to pytest

Introduction to pytest

Slides for my EuroPython 2014 talk on pytest

Andreas Pelme

July 23, 2014
Tweet

More Decks by Andreas Pelme

Other Decks in Programming

Transcript

  1. %FNP#FGPSF import  unittest   ! ! def  upper_reverse(text):    

         return  ''.join(reversed(text.upper()))   ! ! class  TestUpperReverse(unittest.TestCase):          def  test_upper_reverse(self):                  self.assertEqual(upper_reverse('hello'),  'OLLEH')
  2. %FNP"GUFS def  upper_reverse(text):          return  ''.join(reversed(text.upper()))  

    ! ! def  test_upper_reverse():          assert  upper_reverse('hello')  ==  'OLLEH'
  3. 4LJQQJOHUFTUT import  pytest   import  sys   ! ! @pytest.mark.skipif(sys.platform

     ==  'darwin',                                          reason='Feature  Y  not  supported  on  OS  X')   def  test_non_osx():          pass
  4. %FQFOEFODZJOKFDUJPOPGUFTUIFMQFS import  pytest   from  selenium.webdriver  import  Firefox   !

    @pytest.fixture   def  webdriver(request):          driver  =  Firefox()          request.addfinalizer(driver.quit)          return  driver   ! def  test_nix_website_title(webdriver):          webdriver.get('https://nixos.org/nix/')          assert  'Nix'  in  webdriver.title   ! def  test_pytest_website_title(webdriver):          webdriver.get('http://pytest.org/latest/')