Тёмный

Testing Flask Applications with pytest - Patrick Kennedy 

FlaskCon
Подписаться 1,6 тыс.
Просмотров 18 тыс.
50% 1

Testing a Flask application helps ensure that your app will work as expected for your end users. This talk provides an introduction to using pytest for testing Flask applications. Before diving into how to use pytest, this talk explains what should be tested in a Flask application. Next, detailed examples are covered on how to write unit and functional test functions with pytest that are specific to Flask applications. Documentation of the tests is also highlighted using the GIVEN-WHEN-THEN approach. After writing tests, running the tests using pytest (with different options) is presented to demonstrate how easy and powerful pytest is. Examples include verbose mode, running only the last failed tests, and running specific test cases. Next, the concept of fixtures in pytest is presented and detailed examples of how to initialize the state of a Flask application are covered. This section includes properly initializing a Flask application to avoid not having the application context created. Finally, the idea of code coverage is introduced and an example of running coverage.py on a Flask application is demonstrated.
Patrick Kennedy is currently a Software Engineer at Lockheed Martin and author at TestDriven.io
slides:
drive.google.com/file/d/1l2wv...

Наука

Опубликовано:

 

6 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 14   
@taylordiem1055
@taylordiem1055 2 года назад
I’ve been avoiding unit tests for a while, but some of my users are commenting that there are small bugs that are detracting from the tools. This video is tremendously helpful in providing an overview and kickstart to using pytest. Excellent presentation and thank you!!
@sachinfulsunge9977
@sachinfulsunge9977 Год назад
That was a very calming and soothing and relaxing explanation that really consolidates in my mind. Thank you
@DforDeathray
@DforDeathray 2 года назад
Thank you so much, Patrick! I have been struggling with TDD for awhile now. Alot of the concepts really clicked watching this.
@Jak132619
@Jak132619 Год назад
Thanks for the video, good to see a tutorial from a TDD advocate. I agree that Given, When, Then is a good structure to use for the actual code of a test, e.g. GIVEN: instantiate the class / setup functionality WHEN: call the function being tested THEN: assert but I question writing an actual comment of it above the test. If requirements change and therefore this test needs to change, there's a risk that this comment will become a lie if the programmer forgets to update it, however the code will always tell the truth
@villo2553
@villo2553 2 года назад
This is a great presentation. Thanks you so much. You made me more understand about TDD.
@EagerEggplant
@EagerEggplant 2 года назад
Informative and great delivery. Thank you.
@CalicoGoodrich
@CalicoGoodrich 2 года назад
Incredibly helpful presentation! Thank you!
@thisisthebestid
@thisisthebestid Год назад
Great video!
@jerryb707
@jerryb707 2 года назад
This is amazing!
@jakubrudy9372
@jakubrudy9372 Год назад
Thank you, helped a lot!
@kvicar7419
@kvicar7419 2 года назад
So, as the explanation in video wasnt enough for me to understand the yield test_client vs return test_client, could you please provide me some additional explanation of why should we do it like this? Thanks in advance, this is the last puzzle I need to completly understand the concepts of pytest.
@vladislavkorecky618
@vladislavkorecky618 2 года назад
Well the difference between them is actually pretty simple. When you "return" a value, the function that returned the value ends, and no other code in it will be executed. But when you call "yield" you return the value to the function above (just like with "return"), but the code still continues. This is important if you need some sort of a teardown or cleanup. The best example of using "yield" would be with file handling. Imagine that you have a function that opens a certain file and then returns it. But there is a problem, you also have to close the file after you return it. So, you change the "return" statement to "yield" and then call the .close() function below it. Hope that helps!
@kvicar7419
@kvicar7419 2 года назад
@@vladislavkorecky618 Amazing answer Vladislav, highly appreciate that! :)
@jamescat2386
@jamescat2386 7 месяцев назад
unit test did not work 'TypeError: __init__() takes 1 positional argument but 2 were given' :-(
Далее
СМОТРИМ YOUTUBE В МАЙНКРАФТЕ
00:34
Просмотров 1,3 млн
Армия США вошла в Зангезур
04:17
Просмотров 263 тыс.
Pytest Tutorial - How to Test Python Code
1:28:39
Просмотров 179 тыс.
Add Unit Tests to Flask App and API with Pytest
12:50
Professional Python Testing with Mocks
21:19
Просмотров 48 тыс.
How To Write Unit Tests in Python • Pytest Tutorial
35:34
Miguel Grinberg - Flask at Scale - PyCon 2016
3:05:01
Просмотров 54 тыс.
iPhone 14 китайский сборка!
1:00
Просмотров 140 тыс.