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

Testes pythonicos com Py.test

Testes pythonicos com Py.test

Talk presented at Python Brasil [11] - In portuguese

Renato dos Santos Oliveira

November 11, 2015
Tweet

More Decks by Renato dos Santos Oliveira

Other Decks in Technology

Transcript

  1. Oush, quem?! ❏ Renato Oliveira ❏ 4ª Python Brasil ❏

    Labcodes Software Studio ❏ Django Software Foundation ❏ Diretor (por mais algumas horas) de Tecnologia da APyB ❏ Organizador da Python Brasil[10]
  2. “Pytest is a mature full featured Python testing tool that

    helps you to write better programs.” Introdução
  3. Introduction - Asserts com a palavra reservada assert def sum(a,

    b): return a + b def test_sum(): assert sum(1, 1) == 2
  4. Migrando código unittest Antes import unittest def to_upper(text): return text.upper()

    class TestToUpper(unittest.TestCase): def test_to_upper(self): self.assertEqual(to_upper("pug"), "PUG")
  5. Markers Habilidade de adicionar metadata extra aos seus testes ❏

    skipif ❏ xfail ❏ parametrize ❏ você também pode criar
  6. slow test, fast test @pytest.mark.slow def test_slow(): assert 1 ==

    1 @pytest.mark.fast def test_fast(): assert 1 == 1
  7. @pytest.fixture() def webdriver(request): driver = Firefox() request.addfinalizer(driver.quit) return driver def

    test_pug_website_title(webdriver): webdriver.get("http://pycon.pug.pe/XXXVIII/") assert "Encontro do PUG-PE" in webdriver.title def test_python_website_title(webdriver): webdriver.get("http://python.org/") assert "Python" in webdriver.title