This Is How Marie Kondo Sets up Her Pytest

preview_player
Показать описание

In this video, I’m going to walk you through how to set up pytest from scratch in a really simple, minimalistic way - Marie Kondo style!

🔖 Chapters:
0:00 Intro
0:26 Step 1: Install Pytest
1:42 Step 2: Create a Test Directory
2:21 Step 3: Configure VS Code for Pytest
5:04 Step 4: Start Writing Tests
8:45 Step 5: Another Example (List Splitting)
11:15 Step 6: Running Tests in Pytest
14:31 Conclusion & Bonus Tips
15:38 Outro

#arjancodes #softwaredesign #python
Рекомендации по теме
Комментарии
Автор

@ArjanCodes - In your videos, you often run a module, look at the output, make a change, and re-run it, and verbally assert that the result is the same (or different in the desired way). It would be great to see you use pytest for this. This will help cement the practice of using pytest for many up-and-coming developers who watch your channel as they move from crafting scripts to architecting and engineering software. If you stick to this set-up for a while, you can just point to this video each time to remind people how to set it up.

adamfarquhar
Автор

I'll be honest here I did not know of Marie Kondo before this video. I just figured she was some Python-ista that I haven't stumbled upon yet.
So I came here looking for Pytest tips and I ended up down a 3hr rabbit hole organizing my closets and drawers!

markspiezio
Автор

Really like pytest-coverage module for tracking the test coverage IN Vscode. Nice QOL thing to visually see those coverage reports inside vscode.

AehrasYT
Автор

I've been needing to learn PyTest, so this video is definitely welcome!

swolekhine
Автор

Learned some new tricks (-k and -s options) thanks!

langsuan
Автор

This video deserves a like for the Marie Kondo mention alone 😂

adam-btxo
Автор

My preferred way to filter tests are markers. A great way to create suite of test from multiple test modules.

przemysawukasik
Автор

Great video, I am a fan of pytest and I use it to create my unit tests in a easy way. A great feature is parametrized tests, you can test a bunch of escenarios at once using that feature.

CarlosMorenoV
Автор

Thx Arjan for the simple yet instructive tuto! I would love to see a similar one on mypy. I spent half-a-day last Saturday wrestling with mypy, trying to get the same results between 1) running it directly (`mypy .`), 2) through pre-commit and 3) through VScode/Cursor cues. Talk about a type-checking rabbit hole! 😅

keuj
Автор

Combining with pytest-xdist to run tests across cores is another tip. Can really reduce the time you are waiting for tests to complete on larger projects.

iamrodos
Автор

Pytest recognizes test modules also if you name them with "_test" postfix. I find this convention better because then tab completion in terminal makes more sense.

kingdargor
Автор

When using uv, you should run things with `uv run pytest` instead. Running `pytest` by itself works because you've activated the uv venv, but that's not necessary. Using `uv run` also automatically runs `uv sync` too, so you don't need to explicitly refresh your dependencies.

maleldil
Автор

Thanks for the video Arjan! Could you consider a deeper dive into advanced testing topics, like mocks and patches?

quarduroy
Автор

Thanks Arjan for another helpful video. One of the previous ones helped me sort out some pytest config issues I had been having, and this gave me a couple of other useful tips that I wasn't aware of. On a related note, do you ever use TDD in practice? I'm fairly sure that a TDD approach would help me write code with a better design and code that's more easily testable, so I'd be interested to see the occasional example of TDD sneaking into some of the videos.

DavidStocks-xl
Автор

1:04 Instead of putting Ruff as a dependency, you can just use Ruff as a uv tool!

kintama
Автор

@ArjanCodes what are your thoughts on using editable installs for testing?

CecilPhillip
Автор

Hey, this is how I set up my tests! 😅😅😅

Andrumen
Автор

Okay, I need to know this. I want to only use src folders for all my python projects (simple or complex, package or app) along with uv. However, I hate that we need to `from src.x import z` (6:06)

Is there anyway to configure uv to allow `from x import z` instead while keeping the src layout?

ChristopherRucinski
Автор

How can you get pytest to ignore the specific warnings like the one you're encountering in the video?
Like with pycodestyle --ignore=E301, E303 (just an example)

djKeu
Автор

I use Unittest module in Django project, but I want to use pytest instead. I think, this will lead to some headache, since Django uses Unittest by default.
Also, I notices, that you used absolute path for imports in the project in your examples. I get used to use relative path in my projects withing a package, and suppose, that this better, but I'm not sure. There are many supporters for each type of imports.
Would you like to make a video about imports in Python? It's kinda interesting and not easy subject as it seems. With your talent to explain complex things in easy way this video should be great :)

MrVernuk
welcome to shbcf.ru