Unit Tests with Pytest | Flask and Python Backend #5

Поделиться
HTML-код
  • Опубликовано: 27 янв 2025

Комментарии • 24

  • @vahkhachatryan
    @vahkhachatryan 2 года назад +4

    Thank you. This is the best tutorial I've found. It's up to date and I think it covers all major components in just 17 minutes.

  • @eyalbahar9291
    @eyalbahar9291 2 года назад +1

    Super great materials! Im so gratefull i found this channel! Thank you Sergio!!

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  2 года назад

      Thank you. Don't hesitate to share it. Do you think there is some content I'm missing in the playlist about Python and Flask?

    • @eyalbahar9291
      @eyalbahar9291 Год назад

      @@TheDevWorldbySergioLema
      I would love to see how to integrate running tests in the dockefile building the app.
      Also maybe a deepdive into best practices in Mock data, connections and how set up and tear down tests while keeping things running fast

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Год назад

      I'm not sure about the Dockerfile with tests. I don't see the usage.
      About the best practices, I just published a new video, check it: ruclips.net/video/gi7O-aYq6mo/видео.html

  • @nicolascomeron
    @nicolascomeron 2 месяца назад

    Is it not necessary to create another test db to store the initial test data? I mean, in that way, the added data is being stored in the main db or separately? When db.create_all is executed (9:03), it replaces the existing db with real data? Thank you, nice video!

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  2 месяца назад

      What I usually do, is creating different fixtures.
      * The first one (with a scope of session) will create the database tables, and delete all the tables at the end;
      * The second one (with a scope of test) will add some data to the database, and drop all the data at the end;
      This means that each unit test will have initial data and clean up. But the tables will remain for the entire session.
      You can see more details in this conftest: github.com/serlesen/backend-flask/blob/main/tests/conftest.py

  • @michaelelbaz7006
    @michaelelbaz7006 Год назад

    Smart thanks

  • @jamescat2386
    @jamescat2386 Год назад

    i tried this and got the error ' RuntimeError: Working outside of application context.'

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Год назад

      From where are you running the tests?
      If you don't run them from the root folder of your project, you may encounter this error.

  • @davidl3832
    @davidl3832 2 года назад

    Thank you very good video!

  • @samihassan1319
    @samihassan1319 2 года назад

    Thank you it's very good.

  • @kuririn2451
    @kuririn2451 2 года назад

    hi sergio, I think it miss the scope's fixture for app_with_data, otherwise with bigger test it reload data and we lost id of confest.py objects in db

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  2 года назад

      For bigger tests, maybe it's better to create a separate fixture which reload the data.
      For small tests, it's better to avoid reloading every time the data, as it won't change from test to test.

  •  2 года назад

    Hi Sergio, I am very new at testing. I cannot event test for first time. I have a project started and have blueprint and app factory structure similar to yours, but I got ModuleNotFoundError: No module named "name_of_app_folder" every time. Any suggestion?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  2 года назад +1

      Be sure to import everything from the root package, include the tests module in the import part.

    •  2 года назад

      @@TheDevWorldbySergioLema I am doing From app.models import Users .... on the test file inside the tests folder located on the same level as app folder. Each folder as a package with its __init__ file inside. Any suggestion?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  2 года назад +1

      It's very hard to guess the file path, project structure and the imports. I recommend you to create a question in Stackoverflow (with all the details and pieces of code), copy the link here, and I will do my best to answer it as soon as possible.

  • @amritjain8688
    @amritjain8688 2 года назад

    this is good. do you have any git url where you have sample code?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  2 года назад

      Yes, you can find all the examples and more here, github.com/serlesen/backend-flask/tree/chapter_5