Docs suggest to define custom test runner to invoke pytest (thus, related pytest-django functionality) via the manage.py script.
I used the following snippet and everything works as expected:
# manage.py
import sys
from pathlib import Path
import environ
from django.core.management import execute_from_command_line
def main():
if (dotenv_path := Path(__file__).parent / ".env").exists():
environ.Env.read_env(dotenv_path)
if sys.argv[1:2] == ["test"]:
import pytest
sys.exit(pytest.main(sys.argv[2:]))
execute_from_command_line(sys.argv)
if __name__ == "__main__":
main()
What are the advantages of the solution presented in the docs compared to the one above? Thanks in advance for any feedback.
Docs suggest to define custom test runner to invoke
pytest(thus, relatedpytest-djangofunctionality) via themanage.pyscript.I used the following snippet and everything works as expected:
What are the advantages of the solution presented in the docs compared to the one above? Thanks in advance for any feedback.