diogomatoschaves / MyCryptoBot

Open source crypto trading platform to automate trading strategies.
120 stars 25 forks source link

add init files to test folder #136

Closed Newtoniano closed 9 months ago

Newtoniano commented 9 months ago

Closes #135

Newtoniano commented 9 months ago

For the bug specifically, we need these in the exact folders where there is a file with an identical name to another test file that resides somewhere else in the repo. See https://github.com/pytest-dev/pytest/issues/3151 .

Adding them in all folders shouldn't be necessary and isn't recommended by pytest because it this can change the way that pytest discovers and imports the test files, which can lead to unexpected behavior. I tried experimenting the fix suggested here https://github.com/pytest-dev/pytest/issues/3151#issuecomment-1693832968 but without success, I actually get even more import errors and modules not found like that. You can go down a rabbit hole of very confused developers that either suggest adding or removing __init__.py files without a clear explanation on how this import failure is happening.

Honestly, all these things are headaches that I never quite understood fully, and I also think pytest imports modules in a slightly different way from python, I just did the bare minimum needed to import all the tests correctly, but if in the future you're gonna create files with identical names across the microservices or even within the same service, then you might need to add a few more of these init files. If you run tests for each folder separately via cli, nothing should be needed anyway.

The safest approach is probably not to have test files with identical names across the microservices, but since many things are duplicated by design, one might forget.

Newtoniano commented 9 months ago

Do you want to rename the conflicting files to something like test_model_app.py and test_execution_app.py instead? It solves the problem and it's probably a cleaner solution

diogomatoschaves commented 9 months ago

Yeah that is probably a cleaner solution. Can you rename the corresponding data file to test_data_app? In order to keep consistency.

Newtoniano commented 9 months ago

Done, you might want to adopt this schema in the future for all test files so that there is never gonna be any conflict.

diogomatoschaves commented 9 months ago

Nice one 👍 Can you just squash all those commits? As they basically create and then delete the same files.

Newtoniano commented 9 months ago

should be good now