Investigate the need for `@pytest.fixture(autouse=True)`
Follow up from https://github.com/causify-ai/helpers/pull/152#discussion_r1896769789
@pytest.fixture(autouse=True) def setup_teardown_test(self):Is this needed? Originally this was a hack for some glitches in pytest. Can you file an issue and investigate why / if it's still needed?
FYI @gpsaggese @jsmerix
I am not sure what is meant by the word "hack" here. This is a normal mechanism to run stuff before and after a test. There exist multiple such mechanisms to do set-up and tear down work, this is one of the options. For example unittest lib also has some built in options.
@heanhsok let's try to assign issues to GH Projects. E.g., sometimes we can use dev_system-v2.x as placeholder
@sonniki has some mental state. Pls add the link to the doc of why is needed
Here is the doc detailing our current approach and why it was chosen: https://github.com/causify-ai/helpers/blob/master/docs/coding/all.write_unit_tests.how_to_guide.md#use-set_up_test--tear_down_test
Here is the old issue where the problem with the native setUp/tearDown methods was discussed and this fixture solution was proposed and implemented: https://github.com/causify-ai/csfy/issues/3466
Through some readings, here’s my understanding:
Fixture: A fixture is a function that sets up some context or state that tests can use, like initializing resources or creating objects.Autouse: When set to True, the fixture will be automatically used for all tests, even if the test functions do not explicitly request the fixture.- The @pytest.fixture(autouse=True) decorator is used to define a fixture that will automatically be applied to all tests in a test class without explicitly needing to be passed as an argument to the test functions.
- Fixture is a recommended approach for setting up Teardown/Cleanup, which is what we are also doing for our
setup_teardown_testmethod. - Therefore, this approach remains necessary.
In this case, should we close this for now? @sonniki
As far as I am concerned, this approach is indeed completely fine. However, I think it was @gpsaggese who is initially skeptical, not me, so maybe it should be up to him whether we should discuss further or close.
At this point I would just add some of the comments in the documentation https://github.com/causify-ai/helpers/issues/177#issuecomment-2607640349 https://github.com/causify-ai/helpers/issues/177#issuecomment-2619716409 and then close