Refatoração do arquivo test_api.py usando Pytest#81
Open
thisiscleverson wants to merge 5 commits intookfn-brasil:mainfrom
Open
Refatoração do arquivo test_api.py usando Pytest#81thisiscleverson wants to merge 5 commits intookfn-brasil:mainfrom
test_api.py usando Pytest#81thisiscleverson wants to merge 5 commits intookfn-brasil:mainfrom
Conversation
adf2084 to
8352b14
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fiz a refatoração do arquivo
test_api.pypara tentar solucionar a issue #67. Com isso, decidir fechar o pull request #79 que usavaunitteste refiz usando o Pytest.Fixtures
mock_gazette_interface: Essa fixture é responsável por criar o mock para
GazetteAccessInterface. Para poder usar, basta usar como uma função comum:Você pode customizar a interface passando parâmetros para configurá-la:
Exemplo usando mock_gazette_interface:
Exemplo usando mock_suggestion_service_interface:
Essa mesma lógica se replica para
mock_city_interfaceemock_suggestion_service_interface.configure_app: Essa fixture usa mocks pre-definido (default_mock) para fazer configuração automática sem a necessidade de reescrever o configure_api_app. É possível injetar uma interface personalizada usando kwargs, onde cada chave corresponde ao nome de um componente e o valor é o mock personalizado para substituir o padrão.
Exemplo de uso:
freeze_time: Essa fixture usa o plugin pytest-freezegun para facilitar testes que manipulam o tempo. Isso faz com que o tempo seja "congelado" em uma data e hora específica (foi definido a data de
2025-01-01 14:50:03).Como executar os testes
Plugins usados no Pytest
Antes:
Depois: