17
submitted 1 year ago* (last edited 1 year ago) by wesker@lemmy.sdf.org to c/python@programming.dev

Where do your unit tests live? Does is vary, depending on project size? Do you like a flat structure, with test files living alongside everything else? Are you a nested folders person?

I'm curious the practice of others, because I still don't feel like I've found a testing directory structure that satisfies me.

you are viewing a single comment's thread
view the rest of the comments
[-] InsecureSignpost@kbin.social 5 points 1 year ago

For unit tests, I put them within a folder parallel to the source code. The directory in that folder matches the module hierarchy.

A flat structure can work for extremely small projects, but things start to go sideways as the code base grows.

Putting the test files alongside the source files makes it harder work with from a project management perspective:

  • pytest has to check more files when doing discovery, which makes the tests take longer
  • It is significantly harder to configure mypy to a more lenient set of rules for test code.
  • It is harder to package/deploy only the runtime code

If the project is big enough to have integration tests, I prefer to have those in their own folder like the unit test folder. It is possible to mark tests into different categories, but putting them in a dedicated folder makes it is harder for people to forget to mark an integration test.

[-] wesker@lemmy.sdf.org 1 points 1 year ago

Side note, I hadn't tried mypy until your reply mentioned it and made me curious. I love it, and have already integrated it into my editor and pipeline. Thanks!

this post was submitted on 24 Jul 2023
17 points (100.0% liked)

Python

6420 readers
22 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS