okfn-brasil / serenata-toolbox

📦 pip module containing code shared across Serenata de Amor's projects | ** Este repositório não recebe atualizações frequentes **
MIT License
154 stars 69 forks source link

Introduce pytest to help address time issues to run journey tests #142

Closed lipemorais closed 7 years ago

lipemorais commented 7 years ago

What is the purpose of this Pull Request? The purpose of this PR is use pytest to help address the long time running some journey tests usings --durations, this way we know which test takes more time to run.

What was done to achieve this purpose? I changed way we run tests to use pytest.

How to test if it really works? To test it you can just run pytest --verbose --durations=10 --cov-report html tests/unit after install pytest and pytest-cov using pip install pytest pytest-cov.

Who can help reviewing it? @cuducos @jtemporal @anaschwendler

TODO

Yesterday I runned it on my machine and some tests took too long to run

==================== slowest 10 test durations =====================
4185.53s call     tests/journey/test_chamber_of_deputies_dataset.py::TestChamberOfDeputiesDataset::test_fetch_translate_clean_integration
162.20s call     tests/journey/test_federal_senate_dataset.py::TestJourneyFederalSenateDataset::test_journey_federal_senate_dataset
2.23s call     tests/journey/test_chamber_of_deputies_session_start_times_dataset.py::TestSpeechesDataset::test_fetch
1.93s call     tests/journey/test_chamber_of_deputies_official_missions_dataset.py::TestOfficialMissionsDataset::test_fetch
1.88s call     tests/journey/test_chamber_of_deputies_deputies_dataset.py::TestDeputiesDataset::test_fetch
1.66s call     tests/journey/test_chamber_of_deputies_presences_dataset.py::TestPresencesDataset::test_fetch
0.40s call     tests/journey/test_chamber_of_deputies_speeches_dataset.py::TestSpeechesDataset::test_fetch
0.00s setup    tests/journey/test_chamber_of_deputies_deputies_dataset.py::TestDeputiesDataset::test_fetch
0.00s teardown tests/journey/test_chamber_of_deputies_dataset.py::TestChamberOfDeputiesDataset::test_fetch_translate_clean_integration
0.00s teardown tests/journey/test_federal_senate_dataset.py::TestJourneyFederalSenateDataset::test_journey_federal_senate_dataset
========================= warnings summary =========================
cuducos commented 7 years ago

As usual government web API are down on weekends. Gonna re-run tests later (or on Monday)…

cuducos commented 7 years ago

@lipemorais Travis CI is still broken with an HTTP error. Meanwhile would you mind pondering on two possibilities:

lipemorais commented 7 years ago

Maybe document pytest usage in the README.md to assure a similar environment when developing locally and in the CI… what do you think about it?

I will do it soon. :)

Is the HTTP error still some external API that is broken? I checked the url that Toolbox tries to fetch and got 404

Here is the url: http://www.camara.leg.br/cotas/Ano-2009.csv.zip

And a print of what I got: image

@cuducos I will add t

cuducos commented 7 years ago

Travis is green, yay! I think all we need now is a version bump ; )

lipemorais commented 7 years ago

There is a test breaking because this dataset is not available. :'(

http://www.senado.gov.br/transparencia/LAI/verba/2008.csv

lipemorais commented 7 years ago

Hey! @cuducos @jtemporal @anaschwendler do you have any idea about what can I do to fix this? :(

cuducos commented 7 years ago

What about mocking the requests and using tiny fixtures instead?

lipemorais commented 7 years ago

@cuducos this is what we do in unit version of this test.

https://github.com/datasciencebr/serenata-toolbox/blob/master/tests/unit/chambers_of_deputies/test_chamber_of_deputies_dataset.py#L42

cuducos commented 7 years ago

Yep. An IMHO opinion depending on external services to run the suites tests is a problem per se. If I'm not wrong we adopted the journey test this way (depending on external services) as a temporary fix. As this was not a permanent solution and, given that it is broken now, it might be an interesting opportunity to sor that out.

Not sure about what others @anaschwendler @jtemporal @Irio think of that though…

lipemorais commented 7 years ago

Hey, @cuducos @anaschwendler . Looks that it is working now. Could we re run travis?

http://www.senado.gov.br/transparencia/LAI/verba/2008.csv

cuducos commented 7 years ago

Sure thing! Just restarted it ; )

cuducos commented 7 years ago

Hasn't lasted long enough:

$ curl -I  http://www.camara.leg.br/cotas/Ano-2008.csv.zip
HTTP/1.1 404 Not Found
lipemorais commented 7 years ago

Looks now that http://www.camara.leg.br/cotas/Ano-2008.csv.zip is out. :'(

image

lipemorais commented 7 years ago

I just runned it a ALL tests and where all green. :)

GREEN BUILD

Could we rerun it or just merge?

cuducos commented 7 years ago

Yay! May we have a version bump?

lipemorais commented 7 years ago

Yay! May we have a version bump?

Done in a7a2dc2a29dea1975bbe990229248c60cff8f9a1