DEV Community

Discussion on: PyTest with Django REST Framework: From Zero to Hero

Collapse
 
1oglop1 profile image
Jan Gazda

Hi, thanks for the article!
I have a question about the project structure:
If I understand it correctly your structure looks like this

.
├── dj_project
│   ├── apps
│   │   └── app_1
│   └── settings.py
├── manage.py
└── tests
    └── apps
        └── app_1
            └── test_app_1.py
Enter fullscreen mode Exit fullscreen mode

I wonder if you could comment on a different approach where you put tests for each app inside the app, like a so:

.
├── dj_project
│   ├── apps
│   │   └── app_1
│   │       └── tests
│   │           └── test_app_1.py
│   └── settings.py
├── manage.py
Enter fullscreen mode Exit fullscreen mode

Thank you

Collapse
 
sherlockcodes profile image
Lucas Miguel

Hi Jan. You lose the ability of using pytest fixtures on a tree structure. Basically, with pytest, you can make a conftest.py file on a per folder bases and you can add fixtures using your own criteria.

Let me explain myself. Let's suppose I want to use a fixture for all tests for an app (ie: I often make an autouse fixture for mocking api calls in every app and like to use another fixture to unmock it for the app it's managing the utils with API calls for integration tests). If I use the aproach you mention, I'll lose this ability. I of course might be missing more stuff, but it's the first thing that came to my mind. You should still manage to configure pytest to activate autoused fixtures on different projects, but there are many use cases that rely on this particular file structure you may will have to encounter workarounds on pytest conf. If you are really interested in this we can talk about different testing folder structures and pro/cons