File tree Expand file tree Collapse file tree 1 file changed +21
-12
lines changed
libpythonpro/tests/test_spam Expand file tree Collapse file tree 1 file changed +21
-12
lines changed Original file line number Diff line number Diff line change 1+ import pytest
2+
13from libpythonpro .spam .db import Conexao
24from libpythonpro .spam .modelos import Usuario
35
46
5- def test_salvar_usuario ():
6- conexao = Conexao ()
7- sessao = conexao .gerar_sessao ()
7+ @pytest .fixture
8+ def conexao ():
9+ # Setup
10+ conexao_obj = Conexao ()
11+ yield conexao_obj
12+ # Tear Down
13+ conexao_obj .fechar ()
14+
15+
16+ @pytest .fixture
17+ def sessao (conexao ):
18+ sessao_obj = conexao .gerar_sessao ()
19+ yield sessao_obj
20+ sessao_obj .roll_back ()
21+ sessao_obj .fechar ()
22+
23+
24+ def test_salvar_usuario (sessao ):
825 usuario = Usuario (nome = 'Renzo' )
926 sessao .salvar (usuario )
1027 assert isinstance (usuario .id , int )
11- sessao .roll_back ()
12- sessao .fechar ()
13- conexao .fechar ()
1428
1529
16- def test_listar_usuarios ():
17- conexao = Conexao ()
18- sessao = conexao .gerar_sessao ()
30+ def test_listar_usuarios (sessao ):
1931 usuarios = [Usuario (nome = 'Renzo' ), Usuario (nome = 'Luciano' )]
2032 for usuario in usuarios :
2133 sessao .salvar (usuario )
2234 assert usuarios == sessao .listar ()
23- sessao .roll_back ()
24- sessao .fechar ()
25- conexao .fechar ()
You can’t perform that action at this time.
0 commit comments