laike9m / pdir2

Pretty dir() printing with joy:beer:
MIT License
1.33k stars 47 forks source link

tests/test_user_config.py failure #58

Open shenganzhang opened 2 years ago

shenganzhang commented 2 years ago

tests/test_user_config.py::test_invalid_config_1 can run into failure when executing the following commands: pip install pytest-randomly pytest --randomly-seed=1234

laike9m commented 2 years ago

May I ask why you need to test it with pytest-randomly?

shenganzhang commented 2 years ago

This is to improve the robustness of the testsuite.

laike9m commented 2 years ago

Thanks for reporting this. I think this is an issue we need to resolve. Mind take a stab on it?

kshivakumar commented 2 years ago

@laike9m Can I work on this issue?

laike9m commented 2 years ago

@kshivakumar Sure. If you have any questions, let me know

kshivakumar commented 2 years ago

Steps to reproduce Error

Any of the below commands will cause a test case to fail

Observations

Test cases in test_user_config.py fail if the order of execution changes. Specifically, if a test case other than test_default_env_without_config or test_empty_config is executed first, then that test case fails and remaining all pass.

Root Cause Analysis

In our clean fixture, we are unloading pdir related modules in the teardown step. That means, whichever test case executes first, pdir related import statements are not executed inside that test case because the modules are already available. Since the imports are not executed, the config based on new file path is also not loaded.
After the first test case is executed, irrespective of whether it fails or passes, the teardown step in the fixture is executed which unloads the pdir modules giving a clean slate for the second test case.

test_default_env_without_config or test_empty_config use default config values. So, there’s no affect of config file on them, they always pass.

https://github.com/laike9m/pdir2/pull/59 fixes this.