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

Use pytest-django for testing #119

Closed
abhiabhi94 opened this issue Dec 12, 2020 · 10 comments
Closed

Use pytest-django for testing #119

abhiabhi94 opened this issue Dec 12, 2020 · 10 comments
Assignees
Labels

Comments

@abhiabhi94
Copy link
Collaborator

abhiabhi94 commented Dec 12, 2020

Change Type

[ ] Refactor/Enhancement
[x] Testing
[ ] CI/CD
[ ] Other

Proposed Changes

  • only tests that need database access can be marked explicitly -> this will help in reducing the time required to run newer tests.(all test cases that import django's TestCase are implicitly given the database access.)
  • all assertions can be made with the simple assert statement without having to remember assertEqual. assertDictEqual etc
  • all existing tests will continue to run, but may be migrated if need arises.
  • all other performance improvements of pytest can be utilized.
  • tests can be run with pytest command.
@Radi85
Copy link
Owner

Radi85 commented Dec 12, 2020

Hey @abhiabhi94,

Can you please fill Proposed Changes section?

@abhiabhi94
Copy link
Collaborator Author

Other proposed changes is whatever it takes to implement this. There is nothing more that comes to my mind as of now.

Feel free to give any suggestions.

@abhiabhi94
Copy link
Collaborator Author

Hey @Radi85, apart from allowing the import lines to be shorter, is there a reason to add the directory test/example here:

Comment/manage.py

Lines 7 to 8 in 04dfb4f

FILE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(FILE_DIR, 'test/example'))

Modifying python-path will require us to use another pytest plugin, This is not a great deal but just wanted to run this through you before adding it.

@Radi85
Copy link
Owner

Radi85 commented Dec 12, 2020

Feel free to give any suggestions.

As you previously mentioned, using pytest will enhance the test performance by hitting the DB when only needed. Something like this would be sufficient

@Radi85
Copy link
Owner

Radi85 commented Dec 12, 2020

Hey @Radi85, apart from allowing the import lines to be shorter, is there a reason to add the directory test/example here:

Yes because test/example is not in the current package and it should be add to the path before running the tests.

@abhiabhi94
Copy link
Collaborator Author

Yes because test/example is not in the current package and it should be add to the path before running the tests.

yes, I do understand that. What I meant was:

Currently we do:

from post.models import Post

Had we not added this path, we would have to do:

from test.example.post.models import Post

@abhiabhi94 abhiabhi94 self-assigned this Dec 12, 2020
@Radi85
Copy link
Owner

Radi85 commented Dec 12, 2020

I am not sure that would work since test package is not yet recognised by the app. You can give it try.

@abhiabhi94
Copy link
Collaborator Author

It is recognized. test actually happens to me the name of the django project.

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test.settings")

But as of now, this change will require changes to a lot of places now, specifically for all imports and apps module in django. As of now, I'm just ditching in favor of adding a pytest-pythonpath plugin.

@abhiabhi94
Copy link
Collaborator Author

abhiabhi94 commented Dec 12, 2020

Should I include #112 in this? As it is I will have to change the tox file for this.

If yes, in place of python3.8, should be just test python3.9 since it is out now?

@Radi85
Copy link
Owner

Radi85 commented Dec 12, 2020

Should I include #112 in this? As it is I will have to change the tox file for this.

If yes, in place of python3.8, should be just test python3.9 since it is out now?

Yes for both.
Let's go for python3.6 and 3.9 and django2.1, 3.1 and the master branch.

@Radi85 Radi85 added this to the 2.6.0 milestone Dec 12, 2020
abhiabhi94 added a commit to abhiabhi94/Comment that referenced this issue Dec 13, 2020
- also fix some tests that required patching settings.
- reducing time for tox tests by running it for lesser environments(still cover all versions)
- add support for python3.9

fix Radi85#119
fix Radi85#112
abhiabhi94 added a commit to abhiabhi94/Comment that referenced this issue Dec 13, 2020
- also fix some tests that required patching settings.
- reducing time for tox tests by running it for lesser environments(still cover all versions)
- add support for python3.9

fix Radi85#119
fix Radi85#112
abhiabhi94 added a commit to abhiabhi94/Comment that referenced this issue Dec 13, 2020
- also fix some tests that required patching settings.
- reducing time for tests running on travis by running them for lesser environments(still cover all versions)
- add support for python3.9

fix Radi85#119
fix Radi85#112
abhiabhi94 added a commit to abhiabhi94/Comment that referenced this issue Dec 13, 2020
- also fix some tests that required patching settings.
- reducing time for tests running on travis by running them for lesser environments(still cover all versions)
- add support for python3.9

fix Radi85#119
fix Radi85#112
abhiabhi94 added a commit to abhiabhi94/Comment that referenced this issue Dec 14, 2020
- also fix some tests that required patching settings.
- reducing time for tests running on travis by running them for lesser environments(still cover all versions)
- add support for python3.9

fix Radi85#119
fix Radi85#112
@Radi85 Radi85 closed this as completed Dec 26, 2020
@Radi85 Radi85 removed this from the 2.6.0 milestone Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants