Carberra
Carberra
  • Видео 406
  • Просмотров 2 281 582
5 SIMPLE Pytest tricks to improve your tests
In production code, the tests are often as important as the code, if not more. Without proper testing, how will you know if your code will ever work in the wild? In this video, I share five top tips to improve your tests and to make sure they're working properly!
00:00 - Intro
00:41 - Context [1]
01:33 - Parametrization [2]
03:22 - Finding edge cases w/ Hypothesis [3]
05:41 - Tracking coverage w/ pytest-cov [4]
08:17 - Reducing inter-test dependencies w/ pytest-randomly [5]
10:55 - Parallel testing w/ pytest-xdist [6-7]
13:45 - Outro
[1] github.com/Carberra/perfect-python/tree/main/2404-pytest-tricks
[2] docs.pytest.org/en/stable/example/parametrize.html
[3] hypothesis.works
[4] pytest-cov.readthedoc...
Просмотров: 1 861

Видео

Numba makes your code FASTER with ONE decorator
Просмотров 3,7 тыс.День назад
Try Keeper Password Manager free for 30 days, then get 30% off when you upgrade using the code CARBERRA30: www.keepersecurity.com/personal.html - There has been plenty of discussion around Python's new JIT since it dropped, but did you know there are other ways of getting a JIT into Python? One of the simpler ways is by using Numba, which allows you to JIT functions by using a single decorator!...
I baked the Hello World cake (but everything went wrong)
Просмотров 46614 дней назад
It's the channel's 5th birthday, so I thought I'd bake a birthday cake (complete with chocolate sauce)! This isn't just any cake though it's the Hello World cake written in the Chef programming language. In this video we answer the most important question: "How does it taste?!". Chef language specification: www.dangermouse.net/esoteric/chef.html Mike Worth's blog post (Web Archive): web.archive...
Liked Pydantic? You'll LOVE Msgspec
Просмотров 11 тыс.21 день назад
If you've ever needed to work with JSON, TOML, YAML, MessagePack, or even structured data, you'll know how many tools are out there. But what if I told you there was one tool that could do all of those things, complete with a consistent API and with speed as a focus? Well, have I got the treat for you! 00:00 - Intro 00:55 - Working with JSON, TOML, YAML, and MessagePack data [1] 05:38 - Seriali...
Pydantic is OP, here's why
Просмотров 22 тыс.28 дней назад
I've made a video on Pydantic already, but version 2 has since been released, so I thought I would come back to it! You can think of Pydantic as a supercharged dataclasses, with all sorts of functionality even attrs doesn't have. It's great for APIs too! 00:00 - Intro 00:44 - Installing Pydantic [1] 01:12 - Creating models [2] 04:15 - Validating inputs [3] 08:10 - Using Pydantic with an API [4-...
Will Python SKIP these versions?
Просмотров 3,6 тыс.Месяц назад
Sign up to Codecrafters for free, and get 40% off ANY plan when you upgrade! app.codecrafters.io/join?via=parafoxia - Ever since the first public release in 1989, Python has used it's own special flavour of SemVer, but is it now looking to switch to something else? In this video, we look at proposals that might make CalVer for Python a reality. PEP 2026: peps.python.org/pep-2026/ - If you want ...
5 tips for CLEAN Python code
Просмотров 2,8 тыс.Месяц назад
5 tips for CLEAN Python code
Python's contextlib is a HIDDEN GEM
Просмотров 11 тыс.Месяц назад
Python's contextlib is a HIDDEN GEM
Partial functions in Python are SUPER NEAT
Просмотров 4,4 тыс.Месяц назад
Partial functions in Python are SUPER NEAT
SIMPLIFY your code with decorators (+ typing)
Просмотров 3,8 тыс.2 месяца назад
SIMPLIFY your code with decorators ( typing)
Implementing OAuth 2.0 from SCRATCH
Просмотров 1,7 тыс.2 месяца назад
Implementing OAuth 2.0 from SCRATCH
Python has BIOMETRIC support?!
Просмотров 2,2 тыс.2 месяца назад
Python has BIOMETRIC support?!
What's new in Python 3.13?
Просмотров 78 тыс.2 месяца назад
What's new in Python 3.13?
I tried a FREE Copilot alternative
Просмотров 2,3 тыс.2 месяца назад
I tried a FREE Copilot alternative
Python is Awesome - Series 2
Просмотров 1,6 тыс.2 месяца назад
Python is Awesome - Series 2
HYBRID callables in Python?! - Jankfest
Просмотров 1,7 тыс.3 месяца назад
HYBRID callables in Python?! - Jankfest
Python is Awesome - Series 1
Просмотров 3 тыс.3 месяца назад
Python is Awesome - Series 1
Using Redis/Redict/Valkey in Python (2024 tutorial)
Просмотров 1,9 тыс.3 месяца назад
Using Redis/Redict/Valkey in Python (2024 tutorial)
My Visual Studio Code setup! (2024)
Просмотров 2,3 тыс.3 месяца назад
My Visual Studio Code setup! (2024)
Wait, you CAN use braces with Python?!
Просмотров 3,3 тыс.3 месяца назад
Wait, you CAN use braces with Python?!
The history of Visual Studio Code's WORST theme
Просмотров 47 тыс.3 месяца назад
The history of Visual Studio Code's WORST theme
Is Python 4 ON THE WAY?! (April Fools)
Просмотров 3,2 тыс.3 месяца назад
Is Python 4 ON THE WAY?! (April Fools)
Creating, renaming, and deleting branches - Git Good
Просмотров 4424 месяца назад
Creating, renaming, and deleting branches - Git Good
7 COOL Python Easter eggs
Просмотров 2 тыс.4 месяца назад
7 COOL Python Easter eggs
Ignoring files with .gitignore - Git Good
Просмотров 5184 месяца назад
Ignoring files with .gitignore - Git Good
Create an API in 20 MINUTES with FastAPI (2024 tutorial)
Просмотров 1,9 тыс.4 месяца назад
Create an API in 20 MINUTES with FastAPI (2024 tutorial)
Pushing to and pulling from the remote - Git Good
Просмотров 4794 месяца назад
Pushing to and pulling from the remote - Git Good
5 MORE EASY Python optimisations
Просмотров 5 тыс.4 месяца назад
5 MORE EASY Python optimisations
Staging and committing changes - Git Good
Просмотров 6164 месяца назад
Staging and committing changes - Git Good
Creating virtual environments in Python (works with Python 3.12)
Просмотров 2,6 тыс.4 месяца назад
Creating virtual environments in Python (works with Python 3.12)

Комментарии

  • @MarthinusBosman
    @MarthinusBosman 21 час назад

    I'd guess if you have a significant conftest setup that xdist would also slow down significantly, since it needs to run conftest for each process

  • @farzadmf
    @farzadmf День назад

    GREAT video with super useful tips; thank you!

    • @Carberra
      @Carberra День назад

      You're welcome! 😄

  • @jancicruz7
    @jancicruz7 2 дня назад

    2 things that could have been mentioned: - pytest --cov=my_package --cov-report=html : it outputs an html file which color codes coverage and is quite nice visual representation of cov - might not be strictly pytest related, but configuring the testing extension in VS Code enables the tests to be run individually by just clicking on the green "play" button to the left of the functions (next to line numbers), which is super nice, especially when you are writing the test and don't know if it will work, you can just click that button over and over again instead of going to terminal and starting the whole unit test session with the commands.

    • @Carberra
      @Carberra День назад

      Oooo that HTML report type sounds cool, might have to give that a shot when I get the chance.

  • @teprox7690
    @teprox7690 2 дня назад

    2:31: one question: does the test cover the free space between the bananas? 😉You test everytime against your own assumptions... not against the universe.

    • @Carberra
      @Carberra 2 дня назад

      The comment of a true tester!

  • @DuncanBooth
    @DuncanBooth 2 дня назад

    When I write pytest tests I try to pull as much setup/teardown code as possible out into fixtures so the tests themselves don't get obscured by loads of setup/teardown. One slightly sneaky trick is using fixtures to set defaults for other fixtures and overriding them with parametrize. So maybe I have a fixture 'user' that creates a user object used by lots of the tests and that fixture takes another fixture 'permissions'. Most of the tests expect a default set of permissions maybe 'read-only' so the permissions fixture sets up that default. Then tests that need a different set of permissions in the user object use `@pytest.mark.parametrize("permissions", [("read-write",)]` and pull in the `user` fixture with elevated permissions (you don't have to reference the overridden fixture directly in the test, pytest will complain if you parametrize a fixture that isn't used by the test but it's fine if it is only used indirectly). That works well if you only need to override the default in one or two places: if you need to do it more often then you wrap the relevant tests in a class and either redefine the fixture inside the class or use parametrize on the entire class or use multiple files with the defaults in conftest.py and override them as needed in individual files.

  • @pythonwithjames
    @pythonwithjames 2 дня назад

    This is awesome haha, congratulations on 5 years mate!

    • @Carberra
      @Carberra 2 дня назад

      Thanks my guy! Glad you enjoyed it!

  • @Achiii67
    @Achiii67 5 дней назад

    What vsc theme is this? Looks nice

    • @Carberra
      @Carberra 4 дня назад

      Link to a video is in the description.

    • @Achiii67
      @Achiii67 4 дня назад

      @@Carberra Thank you!

  • @xanderplayz3446
    @xanderplayz3446 5 дней назад

    Just use Taichi.

  • @blendfile3_3
    @blendfile3_3 6 дней назад

    i tried Pylance, mypy and pylint. But the Ruff the best what i used

  • @ShootingUtah
    @ShootingUtah 6 дней назад

    Ooh, not sure yet but we use some matrix multiplication functions at work to optimize insurance policies. I bet there's at least a few places numba could significantly speed things up! Right now some larger scenarios with larger input sets take multiple MINUTES to run, if some of those could be brought down to seconds it would not only make our web application more user friendly, it will save a bunch of money in Google cloud function costs. I'll have to do some experimentation and see if they're willing to pay me for the improvements haha!

    • @Carberra
      @Carberra 3 дня назад

      I hope you get the results you're hoping for! Let me know!

  • @jangrygiel9934
    @jangrygiel9934 7 дней назад

    Better way to do this: numbers = [1,2,3,4,5] total = sum(numbers)

  • @neilthomas2549
    @neilthomas2549 9 дней назад

    I used numba on my Mandlebrot code - 45x times speedup per core for a total of 180x speedup

    • @Carberra
      @Carberra 9 дней назад

      Holy cow, that's insane!

  • @warrior100girl
    @warrior100girl 9 дней назад

    "source.organizeImports": true gives error, saying it expects string

    • @Carberra
      @Carberra 9 дней назад

      Change it to: "explicit".

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 9 дней назад

    *Sometimes 😂 Thank you, dude😊

  • @the_loves_humans_guy
    @the_loves_humans_guy 11 дней назад

    have you heard about sum?

  • @joekhames4161
    @joekhames4161 11 дней назад

    you are a great lad

  • @pastnowisaac7997
    @pastnowisaac7997 11 дней назад

    Simple and good, thanks!

  • @VinceKully
    @VinceKully 12 дней назад

    While it’s neat, it was removed from the builtins in python 3 because it’s not very performant, and not that readable (therefore not very pythonic). This example you’ve written is proof of that, because you could just call sum on the list.

  • @shankubisai1370
    @shankubisai1370 12 дней назад

    That was a great explanation. I can see that this a private repo. Could you please share the source code in a public repo.Thanks..!!

  • @dave_jones
    @dave_jones 12 дней назад

    This description is wildly confusing. It would be better to discuss the third optional parameter which is the `initializer` which defaults to the first value of the iterable

  • @paulosergioschlogl9550
    @paulosergioschlogl9550 12 дней назад

    If you use sum it is not so much ease?

  • @KavyanshKhaitan
    @KavyanshKhaitan 12 дней назад

    "So many functions are under this hood" should be the title. I think you made a typo.

    • @largewallofbeans9812
      @largewallofbeans9812 3 дня назад

      he didn't though. In fact, it was YOU who made a typo. You said "under this hood" rather than "this under the hood". That is, unless the title changed.

  • @thomaseb97
    @thomaseb97 13 дней назад

    this isnt quite how filter would realistically should used, its if you're going to loop through something and want to filter your iterator to avoid some logic inside your loop, this is exactly where list comprehensions is supposed to be used though, apples to oranges cprofile is a good thing to use for actually finding speed issues as it sees which functions is adding time to your program, this is just benchmarking (which should include variable length lists)

  • @gabrielfougeron6007
    @gabrielfougeron6007 14 дней назад

    Hey. For benchmarking in python, I highly recommend the Foss project pyquickbench

  • @keerthi5051
    @keerthi5051 14 дней назад

    Thanks for explaining with the application along with the Syntax 🙂

  • @kaperome
    @kaperome 14 дней назад

    Thanks for the video. Why do you use the minimum instad of the mean or median to compare both approaches?

    • @Carberra
      @Carberra 14 дней назад

      Averaging the results would include those outliers, making the test results less accurate (unless of course you did some work to remove outliers, then an average would be more accurate). It's mainly done to get rid of any variance that may be caused by the first run -- I've seen it before where the fastest time out of two tests was always the one that ran second, irrespective of the code, due to startup shenanigans.

    • @Fuzbo_
      @Fuzbo_ 12 дней назад

      ⁠@@Carberra Using the “min” value could also be an outlier no? In a real example, you’d almost certainly want to do a statistical test (e.g. using scipy.stats.ttest_ind) to analyze if one implementation was faster. Even then there are other variables to consider, but generally speaking it would provide a reasonable analysis of the two approaches

    • @lukaswalker2342
      @lukaswalker2342 11 дней назад

      ​​@@Carberrathen you should use median and not min what is the logic here??

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 14 дней назад

    Thank you 😊

  • @murphygreen8484
    @murphygreen8484 15 дней назад

    If you do it again you might try creaming your butter and sugar together first. Then the dry and liquid ingredients get mixed separately before combined. The cream doesn't have to be hot before going into the tempered chocolate if you add it in very slowly and mix the whole time you are adding it. If you have too much egg I would mix it first before pouring any out so it's homogeneous first. - source: guy who watches a lot of cooking shows but never bakes himself

    • @Carberra
      @Carberra 14 дней назад

      Thanks for the tips my guy! Baking is certainly not something I do often so don't have too much knowledge (though my mum is very good with it), but certainly isn't something I dislike, so perhaps I should do more. There's a _chance_ doing my first baking in years while also trying to record it perhaps was never gonna go perfectly 😅 Though added to the chaos, so worth it!

    • @murphygreen8484
      @murphygreen8484 14 дней назад

      @@Carberra was certainly fun to watch and it looked like you had fun doing it. That's all that really matters

    • @Carberra
      @Carberra 14 дней назад

      Yeah it was! I always have fun doing these special videos, and I even got a cake out of this one! I'm glad you enjoyed it too 😄

  • @DuncanBooth
    @DuncanBooth 15 дней назад

    You can measure liquids more accurately using the scales. Density of double cream is apparently about 1.01g/ml so 54ml would be 54.5g. Beaten eggs have a density between 1.03g/ml and 1.1 (weight required left as an exercise for the reader). Nice little Denby bowl btw, we have a full set of those and it's the first time I've seen anyone else with that design.

    • @Carberra
      @Carberra 14 дней назад

      Yeah I thinking about that, but didn't really know how plausible that would be. I had no idea double cream was basically 1:1 though, that would've definitely been easier! Denby bowl (and the rest of the Denby -- I believe the collection is called Memories) is my mum's and she absolutely adores it. We have a full set as well! You can actually still get them, albeit second hand -- we did that recently cos we needed a few more plates. Not too expensive either, considering it's Denby anyways.

    • @DuncanBooth
      @DuncanBooth 13 дней назад

      @@Carberra Tell your mum she has impeccable taste.

  • @nimamasoumi646
    @nimamasoumi646 16 дней назад

    thank u so much mate, really helped me out

  • @mjackstewart
    @mjackstewart 17 дней назад

    Does it include Michaelmas?

  • @Martin-delta
    @Martin-delta 17 дней назад

    So this is a tradition now right? I will mark my calendar 🎉

  • @venom_snake1984
    @venom_snake1984 17 дней назад

    Congrats Carberra! Keep up the good work!

  • @JorgeEscobarMX
    @JorgeEscobarMX 17 дней назад

    A short worth while saving🎉

  • @rethanon
    @rethanon 17 дней назад

    Congrats on reaching 5 years, here's to another 5 more!

  • @machadinhos
    @machadinhos 17 дней назад

    Happy birthday!