freedomofpress / dangerzone

Take potentially dangerous PDFs, office documents, or images and convert them to safe PDFs
https://dangerzone.rocks/
GNU Affero General Public License v3.0
3.35k stars 152 forks source link

tests: remove fixture imports in the tests #813

Closed almet closed 3 weeks ago

almet commented 1 month ago

Fixtures should find their way by themselves, as mentioned in the pytest docs.

You don’t need to import the fixture you want to use in a test, it automatically gets discovered by pytest. The discovery of fixture functions starts at test classes, then test modules, then conftest.py files and finally builtin and third party plugins.

The tests are currently failing, I believe because of the way they are run. I'm exploring how to use pytest xdist to have them run in separate processes.

almet commented 1 month ago

The tests are currently failing, I believe because of the way they are run. I'm exploring how to use pytest xdist to have them run in separate processes.

It turns out the tests weren't able to import the fixtures because they were not defined in the correct conftest.py file, where pytest is looking for them. I moved them (and the other utilities that were lying in the __init__.py files, which hopefully should be enough for it to work.

almet commented 1 month ago

I believe the current tests are failing because of #801, so it is not related to these changes.

I would be interested to have more information about why the tests were run in separate processes, as mentioned in https://github.com/freedomofpress/dangerzone/issues/493.

Especially, I would like to try to reproduce the issue, as the changes on how we load and use the fixtures might fix it.

apyrgio commented 4 weeks ago

The tests pass locally in my machine. However, if I specifically try to run pytest -v tests/gui/ (at least in Ubuntu Focal), it fails. Are you seeing something similar?

almet commented 3 weeks ago

The tests pass locally in my machine. However, if I specifically try to run pytest -v tests/gui/ (at least in Ubuntu Focal), it fails. Are you seeing something similar?

I can't reproduce, (un)fortunately, Here are the comments I'm running and the output:

./dev_scripts/env.py --distro ubuntu --version focal build-dev
./dev_scripts/env.py --distro ubuntu --version focal run --dev bash -c "cd dangerzone; poetry run pytest -v tests/gui"
apyrgio commented 3 weeks ago

Interesting, I rebuilt my Ubuntu Focal dev environment, and I can't reproduce it as well. It could be due to the PySide6 / Python3 update. Let's hope we'll never have to find out :slightly_smiling_face:

Feel free to merge, thanks!