Getting Started With Testing in Flask

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • In this video I introduce integration testing a Flask app. You'll learn how to use the test client and how to mock API requests inside a test among other things.
    Get the code I wrote in this video: prettyprinted....
    Need one-on-one help with your project? I can help through my coaching program. Learn more here: prettyprinted....
    Twitter: / pretty_printed
    Github: github.com/pre...

КОМЕНТАРІ • 32

  • @karlduckett
    @karlduckett Рік тому +10

    Thanks Anthony - glad you are still creating Flask / Python videos.

    • @prettyprinted
      @prettyprinted  Рік тому +5

      I don't plan on stopping anytime soon. Thanks for watching.

  • @zhengliu3362
    @zhengliu3362 9 місяців тому +3

    One strange thing: it seems the login form does not have an CSRF token. I think it's oversimplified here due to lack of the token. How do you test login and register if the login form in login.html has this token?

  • @rastaricky9584
    @rastaricky9584 Рік тому +1

    Thank you! You are an AMAZING teacher!!!

  • @yomajo
    @yomajo Рік тому +1

    Thanks for vid! Have a question... Lets say flask app is dockerized. Uses rq worker, redis, postgres as compose services. How should one thing about testing such application?

    • @prettyprinted
      @prettyprinted  Рік тому +1

      The main tests of your routes shouldn't change. But you could also have end-to-end tests that test everything. I'd make my project generic enough to deploy to a testing server (from something like Github actions), and then I'd use Playwright to test my app from the outside like a user.

  • @biswajit-k
    @biswajit-k Рік тому +1

    Thanks Anthony, very helpful and informative :)

  • @mutsukira
    @mutsukira Рік тому +1

    Thank you, simple and clear.

  • @JayZhang-hf7lu
    @JayZhang-hf7lu 7 місяців тому

    This is super helpful! How do you clean the database everytime you finished testing though? I found the memory sqlite always keeping data

  • @jaredbarber2824
    @jaredbarber2824 Рік тому +1

    Do you have a video where you made the app? I can't get it to run.

  • @alexanderantonio5239
    @alexanderantonio5239 5 місяців тому

    so far I have got that tests are made to test a functionality. Do tests need to always pass or always fail??

  • @luisleon4817
    @luisleon4817 Рік тому

    Thank you man, you are the python man

  • @rangabharath4253
    @rangabharath4253 Рік тому

    Awesome as always 😀

  • @papercut._.
    @papercut._. Рік тому

    You're a legend!

  • @amar101_16
    @amar101_16 Рік тому

    Very helpful... Thanks a lot

  • @soyciro4623
    @soyciro4623 Рік тому

    Pretty cool video! Please keep it up!

  • @GraemeMeyer
    @GraemeMeyer 6 місяців тому

    Really wish you'd mentioned it was Mac only up front

  • @wintermute3d
    @wintermute3d Рік тому

    Quality content! Thanks a lot

  • @egekaplann
    @egekaplann 7 місяців тому

    So zen… Beautiful

  • @cantis
    @cantis Рік тому

    So this is doing tests against an in memory database vs mocking… is there a guideline for this?

  • @walkdead94
    @walkdead94 Рік тому

    Thank you! I'm not sure what do you use to login, but I really wanted to know how to test the login/logout behavior

    • @adaum79
      @adaum79 20 днів тому

      He uses the Flask Login extension

  • @drac8854
    @drac8854 Рік тому

    Can we have a comman database for all the test.
    For example if i want to test comment functionality
    Wherein user 1 adds a post and user 2 comments in it
    Not sure if that would be possible in this type where database is created for every test.

    • @prettyprinted
      @prettyprinted  Рік тому +1

      Yes you can. In Pytest there are the ideas of scopes, which construct when the fixture is destroyed. So for the app fixture, it gets destroyed after every function by default. But you can change this to things like module, class, or session. Then the database will persist between tests.

  • @mahmoudessam7525
    @mahmoudessam7525 Рік тому

    Thanks a lot :)

  • @dmbrv
    @dmbrv Рік тому

    nice