Python Testing 101 with pytest

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ธ.ค. 2024

ความคิดเห็น • 41

  • @RandomAlexus
    @RandomAlexus 4 ปีที่แล้ว +53

    I guess this guy always gives his presentation in... Layman's terms.

    • @MattLayman
      @MattLayman  4 ปีที่แล้ว +30

      Yep. In fact, that was the name of my first blog! Let's just say I've heard that joke many times since middle school. :)

    • @RandomAlexus
      @RandomAlexus 4 ปีที่แล้ว +7

      Also, fantastic presentation.

  • @kazmkazm9676
    @kazmkazm9676 2 ปีที่แล้ว

    Thank you for providing this high-quality content.

  • @dubey_ji
    @dubey_ji ปีที่แล้ว

    Just found your channel really good content
    Thank you so much for this

  • @tptp200
    @tptp200 5 ปีที่แล้ว +12

    Your tutorial is really really great.
    Thank you very much ^^

  • @TheSamuelBauter
    @TheSamuelBauter 2 ปีที่แล้ว

    Great incremental introduction to pytest for beginners. Well done!

    • @MattLayman
      @MattLayman  2 ปีที่แล้ว +1

      Thanks! I'm glad you liked it!

  • @ToddCunningham
    @ToddCunningham 5 ปีที่แล้ว +12

    Great presentation, Matt. Looking forward to more meetings.

  • @bobsmall2870
    @bobsmall2870 3 ปีที่แล้ว

    @ 16:58 I tried running the test on pytest 6.2.2 and it errored due to the '----' before the assert. I replaced this with a space and it worked.

  • @SleepyBoBos
    @SleepyBoBos 4 ปีที่แล้ว

    Good code is able to adapt to change. Unit testing is a way to assist with having as high a rate of changes as possible.

  • @hysteresis4222
    @hysteresis4222 3 ปีที่แล้ว

    Nice entry level point to using pytest. Thank you.

  • @philippefutureboy7348
    @philippefutureboy7348 5 ปีที่แล้ว +3

    Great presentation Matt! Quick question for you: At 41:20 why do you check the type using isinstance(value, numbers.Number) instead of ‘type(value) is int or type(value) is float’? I’m brand new to Python so these are the kind of nuances that give a better insight into best practices of experienced Pythonistas. Thanks a lot!

    • @MattLayman
      @MattLayman  5 ปีที่แล้ว +6

      The primary reason was because numbers can be more than ints and floats. By checking against numbers.Number, it becomes possible to check a bunch of different number types. docs.python.org/3.8/library/numbers.html#numbers.Number has more details.
      Also, it is recommended that code check with isinstance (docs.python.org/3/library/functions.html#isinstance). I would guess it's for speed reasons, but you could also check multiple types at one like isinstance(value, (int, float)).
      Good luck on your journey into Python!

  • @guidedbyreason3619
    @guidedbyreason3619 4 ปีที่แล้ว +2

    Thanks a lot Matt! Very thorough tutorial. Appreciate it greatly :)

  • @raviranjannandan
    @raviranjannandan 5 ปีที่แล้ว +2

    Great presentation, Matt. got to learn a lot on pytest and python

  • @ssaran2
    @ssaran2 3 ปีที่แล้ว

    Thank you Matt!

  • @RevantGuptaa
    @RevantGuptaa 4 ปีที่แล้ว

    Clear and crisp explanation. Thanks.

  • @AnshulChauhan95
    @AnshulChauhan95 5 ปีที่แล้ว +1

    Thanks a lot, Matt

  • @pavelow36
    @pavelow36 4 ปีที่แล้ว

    fantastic. just what I need. thanks vmuch!

  • @LLlEPEMETbEB
    @LLlEPEMETbEB 4 ปีที่แล้ว +1

    Hi Matt, thank you for awesome presentation! Could you please describe how you make the vim shows hyphen instead spaces in insert mod?

    • @MattLayman
      @MattLayman  4 ปีที่แล้ว +3

      Certainly. I've included this setting in my vimrc file: set list listchars=tab:>-,trail:-
      It will show my tabs and any trailing spaces as hyphen characters.

  • @johndoe-lz8fo
    @johndoe-lz8fo 3 ปีที่แล้ว

    please help, just received this error and dont know what it means. TypeError: required field "lineno" missing from alias

    • @MattLayman
      @MattLayman  3 ปีที่แล้ว

      TH-cam is not a great place to provide tech support (nor do I have much to investigate the errors for other people). In the spirit of teaching a man to fish, I'll try to make a couple of suggestions which may help. 1) Search Google for the *exact* error message that you (from "TypeError" to "alias"). Those results can often provide exact answers to a problem. 2) Search on StackOverflow. If you can't find an answer after searching, create a question and you may get a group of people of are ready and able to help. Good luck!

    • @johndoe-lz8fo
      @johndoe-lz8fo 3 ปีที่แล้ว

      @@MattLayman thanks for the reply but i just figured it out. i has to uninstalled pytest and install the new version.

  • @Balkac
    @Balkac 5 ปีที่แล้ว +1

    Very nice presentation, as far the best about pytest I have found.
    Anyway. As was said, this was a sample of unit testing. And I'm wondering if these frameworks (pytest, unittest) are really recommended for some complex integration/end-to-end test of applications/systems (doesn't matter if frontend or backend).
    For example I'm working on backend end-to-end tests and I have never use framework like this because I just can't imagine I would need to write separate function for every test case (my test suite contains like 3500 test cases at this moment). I developed my own test framework, but companies and business always push to use well-known frameworks for testing. So what is the solution? :)

    • @MattLayman
      @MattLayman  5 ปีที่แล้ว

      Before I start, I'll note that I don't claim to have *the* solution. :)
      My guess is that companies want to use well established frameworks to leverage the network effect. Pytest is now the de-facto testing tool in the Python ecosystem. With that position and its architecture, there is a rich set of plugins designed to handle a wide variety of testing scenarios. My suggestion would be to look for plugins that might help.
      Also, one topic that I didn't cover here is pytest fixtures. fixtures are a fantastic tool for doing test setup and can probably go a long way with helping in end-to-end testing. Good luck!
      Oh, one last thing, if things are working well for you with unittest, I think you can stick with it! There are plenty of teams that use unittest, nose, trial, or some other testing framework. I probably wouldn't recommend switching a massive test suite to a new tool. That is a lot of effort with a minimal payoff.

    • @Balkac
      @Balkac 5 ปีที่แล้ว

      @@MattLayman Hello, thanks for the answer. The point is that I`m not using any known framework. As I was not satisfied with unittest at the begining, I decided to create my own such a framework, which works pretty well for me and for the project. But of course this is not very happy solution for ... nobody :) Maybe I need to look for some another plugins ...

    • @abc-code6
      @abc-code6 5 ปีที่แล้ว +1

      hi,
      pytest as Testframework is good one, you can use even GUI automation using selenium.
      > General purposes of a test frameworks:
      1) Test collection: pytest decide a root directory based on some logic, more generally a directory where pytest.ini resides. Then collect all the tests following some naming convention, by default any it expect test name and module name should start with test_
      Test collection modification: if you want modify the collection, say want to skip some tests which are not yet implemented fully, you have pytest hook pytest_collection_modifyitems()
      2) SetUp&Teardown: You can use pytest fixtures to do this activity, you can provide scope for setup/teardown, like if you want to run the setup beginning of each test, or beginning of module, or session.
      3) Reporting: pytest verbose give you good information regarding the reason behind any failure. it has pytest-html plugin to generate html report. You can also use allure plugin for reporting.
      4) Test suite: you can use markers to mark tests, like pytest.mark.regression , you can run pytest to execute all the test marked as regression.
      5) Parameterization: you can run same test based on different parameter, for that you can use pytest fixture, or marker or ddt package for data driven testing.
      6) parallel processing: pytest has pytest-xdist plugin to run test in parallel.
      Thanks,
      Swapan.

    • @ashrafm.5627
      @ashrafm.5627 5 ปีที่แล้ว

      @@abc-code6 teach me GUI testing with pytest?

  • @akkineniajay8117
    @akkineniajay8117 5 ปีที่แล้ว +6

    I know you are time constrained, it would have been amazing if you had covered markers and fixtures as well. Thanks. Its a nice demo.

    • @MattLayman
      @MattLayman  5 ปีที่แล้ว +11

      That's a good suggestion! Maybe I'll make a Python Testing 201 presentation in the future to explore some of those more advanced topics.

    • @RedShipsofSpainAgain
      @RedShipsofSpainAgain 3 ปีที่แล้ว +2

      Agreed. Diving into Fixtures and Mocks would be super helpful. Thanks Matt!

  • @Jakobowsky
    @Jakobowsky 4 ปีที่แล้ว

    Great presentation! Love it

  • @nareshgb1
    @nareshgb1 5 ปีที่แล้ว +1

    Very well explained.....great presenting style.

  • @miketwenty1
    @miketwenty1 5 ปีที่แล้ว

    ZeroDivisionError seems to be passively caught and the result set to == 0 on version 3.7.3
    Thanks for the quick tutorial with pytest and python.

    • @MattLayman
      @MattLayman  5 ปีที่แล้ว

      Thanks! I hope it was helpful.

    • @miketwenty1
      @miketwenty1 5 ปีที่แล้ว +1

      @@MattLayman your 201 was also great.. thanks so much.. I feel like a pro now.. ;)

  • @bruriahassidim8369
    @bruriahassidim8369 4 ปีที่แล้ว

    Thanks a lot

  • @doyourealise
    @doyourealise 5 ปีที่แล้ว

    amazing video subscribed

  • @Xaminn
    @Xaminn 3 ปีที่แล้ว

    where mom jeans