allenai / mmda

multimodal document analysis
Apache License 2.0
158 stars 18 forks source link

Egork/vila unitet test to class #169

Closed egork520 closed 1 year ago

egork520 commented 1 year ago

Moving unite tests to the class. Locally pytest test would fail on this file

soldni commented 1 year ago

Hey @comorado, I am not sure if it recommended to move directories during testing: I can imagine introducing a bug during tests that is caused by a previous test moving to a different directory.

In tests I've authored, I use __file__ to get an absolute path to fixtures, e.g. see tests/test_parsers/test_override.py.

Some StackOverflow answers recommend creating functions pointing to paths and decorating them with @pytest.fixture

egork520 commented 1 year ago

Hey @comorado, I am not sure if it recommended to move directories during testing: I can imagine introducing a bug during tests that is caused by a previous test moving to a different directory.

Good point @soldni, that's the reason why I had it in setUp method. setUp is run prior to running each individual test https://stackoverflow.com/questions/6854658/explain-the-setup-and-teardown-python-methods-used-in-test-cases

In tests I've authored, I use __file__ to get an absolute path to fixtures, e.g. see tests/test_parsers/test_override.py. I like your suggestion and instead of changing the directories I will create a class variable which points to the fixtures path.

Some StackOverflow answers recommend creating functions pointing to paths and decorating them with @pytest.fixture

A bit too fancy, thank you for the pointer :)

egork520 commented 1 year ago

Hey @comorado, I am not sure if it recommended to move directories during testing: I can imagine introducing a bug during tests that is caused by a previous test moving to a different directory.

Good point @soldni, that's the reason why I had it in setUp method. setUp is run prior to running each individual test https://stackoverflow.com/questions/6854658/explain-the-setup-and-teardown-python-methods-used-in-test-cases

In tests I've authored, I use __file__ to get an absolute path to fixtures, e.g. see tests/test_parsers/test_override.py. I like your suggestion and instead of changing the directories I will create a class variable which points to the fixtures path. Some StackOverflow answers recommend creating functions pointing to paths and decorating them with @pytest.fixture

A bit too fancy, thank you for the pointer :)

@soldni I've pushed a commit where I am creating a path variable. Still doing it though in the setUp method. On the pytest run time each individual test receives it's version of the setUp variables. So for example if self.doc was modified in one test, another test is not going to see the modifications because it receives its version of the self.doc created by the setUp class.