mkalioby / django-mfa2

A Django app that handles MFA, it supports TOTP, U2F, FIDO2 U2F (Webauthn), Email Token and Trusted Devices
MIT License
301 stars 44 forks source link

Add tests #78

Open oussjarrousse opened 10 months ago

oussjarrousse commented 10 months ago

I suggest adding tests with PyTest.

If you like the idea, and you approves I will volunteer to create the boilerplate and the first few tests.

mkalioby commented 10 months ago

Sure but wont it better to use Django test

oussjarrousse commented 10 months ago

Yes good point.

I have used both Django tests (based on unittest) as well as PyTest (with the pytest-django plugin) to add tests to Django projects.

My experience with PyTest is much better, not only in Django project, but also in all kinds of Python projects.

I think there are several reasons for that, for instance pytest makes organising tests much simpler and much flexible than unittest. It also make parameterising tests much simpler. It also more economic in terms of lines of code, and in case you already have tests written for unittest, pytest can still run them...

Here are two articles with some pros. of using pytest for testing Django: https://djangostars.com/blog/django-pytest-testing/ https://jmr.pl/blog/pytest

I also want to refer you to this stackoverflow Q/A: https://stackoverflow.com/questions/44558018/django-test-vs-pytest (note that the issue the author mentions with gitlab-ci.yaml is rather lack of experience of the author with pytest than a real issue... basically he does not know about tox or hatch)

mkalioby commented 10 months ago

Ok your call.

On Sun, 24 Dec 2023, 18:11 Oussama Jarrousse, @.***> wrote:

Yes good point.

I have used both Django tests (based on unittest) as well as PyTest (with the pytest-django plugin) to add tests to Django projects.

My experience with PyTest is much better, not only in Django project, but also in all kinds of Python projects.

I think there are several reasons for that, for instance pytest makes organising tests much simpler and much flexible than unittest. It also make parameterising tests much simpler. It also more economic in terms of lines of code, and in case you already have tests written for unittest, pytest can still run them...

Here are two articles with some pros. of using pytest for testing Django: https://djangostars.com/blog/django-pytest-testing/ https://jmr.pl/blog/pytest

I also want to refer you to this stackoverflow Q/A: https://stackoverflow.com/questions/44558018/django-test-vs-pytest (note that the issue the author mentions with gitlab-ci.yaml is rather lack of experience of the author with pytest than a real issue... basically he does not know about tox or hatch)

— Reply to this email directly, view it on GitHub https://github.com/mkalioby/django-mfa2/issues/78#issuecomment-1868550206, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPOPRAMRKUTEFT7SPRSPTTYLBH37AVCNFSM6AAAAABBAZVROOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRYGU2TAMRQGY . You are receiving this because you commented.Message ID: @.***>

oussjarrousse commented 10 months ago

I've created a pull request #79 that addresses this issue! looking forward for your feedback!