Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert all tests to pytest #468

Open
sliverc opened this issue Aug 29, 2018 · 12 comments
Open

Convert all tests to pytest #468

sliverc opened this issue Aug 29, 2018 · 12 comments
Assignees
Labels

Comments

@sliverc
Copy link
Member

sliverc commented Aug 29, 2018

Currently some tests are written in unit test and some in pytest.

As pytest is more flexible all tests should be converted to use pytest to be consistent.

It also needs to be considered whether pytest_runner in setup.py is really a good thing or whether just simply running pytest would not be more "pytesty".

@n2ygk
Copy link
Contributor

n2ygk commented Aug 31, 2018

Is this consistent with Django's testing guidelines? It appears to prefer unittest. This is, after all, a Django-centric project.

@sliverc
Copy link
Member Author

sliverc commented Sep 4, 2018

what we use internally for testing doesn't affect the user so that's up to DJA to decide.

We simply have to make sure that a DJA user can use unittest to write tests. DJA already supports this by allowing DRF testing configuration.

Why pytest over unittest:
unittest is a Java construct copied into the python world where as pytest has been written with Python in mind and makes writing test so much simpler (especially the fixture part)

Also see pytest-django for more details.

@n2ygk
Copy link
Contributor

n2ygk commented Sep 4, 2018

I guess my point is that as a "Django developer" I would prefer to use the Django core mechanism for testing unless there's a strong reason to do otherwise. I have found the tests in DJA to be quite confusing given the mixture of styles. But I don't have a lot of experience with python testing frameworks....

@sliverc
Copy link
Member Author

sliverc commented Oct 16, 2020

Whenever I review PRs or write PRs myself the most apparent issue of DJA is that the testing code is very messy and confusing for contributors how to write a test and where.

The issues I see at this point:

  • mixed styles of tests (Pytest, Unittest)
  • mixture between example app and test itself
  • unclear naming
  • test data shared across several modules (once test data needs to be adjusted totally unrelated tests fail)
  • relatively low test coverage

I might have some time at hand to work on this. First I want though that we agree on how to do it before I start.

Following points I see as a way forward:

  • create tests module where test will reside (like in DRF)
  • use pytest styled tests
  • each module defines its own test data
  • use snapshot testing where applicable
  • strip of the example app of all test related items
  • aiming at 100% test coverage or otherwise mark code with no cover if testing is not applicable.

This can be done gradually. So test module by test module can be moved to tests and converted to pytest. Once all is done the example app can be cleaned up

@n2ygk This issue has been open for a while and the main issue here I guess was whether we can agree on converting tests to pytest . My point is that pytest has been around quite a while in the Python community and has been well established. In my experience it makes writing tests much simpler. And if we take the effort to clean up the tests we should also take the opportunity to convert them to pytest style.

What is your take on this? Also comment on what you think is important when cleaning up the tests which I might not have mentioned yet.

@n2ygk
Copy link
Contributor

n2ygk commented Oct 16, 2020

@sliverc I agree with all your points 100%.

@auvipy
Copy link
Contributor

auvipy commented Oct 17, 2020

django rest framework suggest pytest like asserts

@auvipy
Copy link
Contributor

auvipy commented Sep 13, 2021

anything required? or we are ok to close it

@sliverc sliverc self-assigned this Sep 13, 2021
@sliverc
Copy link
Member Author

sliverc commented Sep 13, 2021

there is actually a long way till this issue is closed. Goal is that all tests in example/tests will be converted to pytest style and moved to tests folder. Do not have much time at hand but will continue to work on this step by step. Assigned it to me so this is clear.

@auvipy
Copy link
Contributor

auvipy commented Sep 13, 2021

if you want helping hand i can do some. i did something like this to DRF

@auvipy
Copy link
Contributor

auvipy commented Oct 21, 2021

there is actually a long way till this issue is closed. Goal is that all tests in example/tests will be converted to pytest style and moved to tests folder. Do not have much time at hand but will continue to work on this step by step. Assigned it to me so this is clear.

you can use me as helping hand.

@sliverc
Copy link
Member Author

sliverc commented Oct 21, 2021

@auvipy Thanks for the offer. Currently it is not 100% clear how the conversions of the tests will happen. So usually while I am converting some tests I figure out on the way best practices. So for now I think it makes most sense I keep working on it.

I think at a later stage help to work on a cleaning-up example app would certainly be appreciated. But this cannot happen as long as the tests are still depending on the example app.

@auvipy
Copy link
Contributor

auvipy commented Oct 21, 2021

ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants