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

Create test for the django app #35

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Create test for the django app #35

wants to merge 4 commits into from

Conversation

l1storez
Copy link
Collaborator

@l1storez l1storez commented Sep 24, 2021

Add running tests as a separate job in GHA CI/CD soon
#27

@l1storez
Copy link
Collaborator Author

l1storez commented Oct 1, 2021

I need help with tests/views_test.py:10:0: E0401: Unable to import 'blog.models' (import-error). I specified the path(
from blog.models import Post), but I get an error. I don't understand what is the problem.

@l1storez l1storez force-pushed the feature/tests branch 2 times, most recently from 8ae260a to 64c25a8 Compare October 1, 2021 20:40
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@webknjaz
Copy link
Member

webknjaz commented Oct 4, 2021

I need help with tests/views_test.py:10:0: E0401: Unable to import 'blog.models' (import-error). I specified the path( from blog.models import Post), but I get an error. I don't understand what is the problem.

This is a linting error. You're probably running pylint in a wrong way. I have no idea what you're doing.

But the error visible in the CI is

Traceback (most recent call last):
  File "/home/runner/work/django-girls-blog-l1storez/django-girls-blog-l1storez/manage.py", line 12, in main
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/work/django-girls-blog-l1storez/django-girls-blog-l1storez/manage.py", line 23, in <module>
    main()
  File "/home/runner/work/django-girls-blog-l1storez/django-girls-blog-l1storez/manage.py", line 14, in main
    raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

This one is happening because you run a script that imports django before you actually installed django.

tests/models_test.py Outdated Show resolved Hide resolved
@l1storez
Copy link
Collaborator Author

l1storez commented Oct 4, 2021

Okay, I separate into another PR

@l1storez
Copy link
Collaborator Author

l1storez commented Oct 4, 2021

I have no idea what you're doing.

I try to do a commit(git commit), but I always get this error

@l1storez
Copy link
Collaborator Author

l1storez commented Oct 5, 2021

I try to do a commit but

Module models_test
tests/models_test.py:9:0: E0401: Unable to import 'blog.models' (import-error)

@l1storez
Copy link
Collaborator Author

l1storez commented Oct 5, 2021

fixing the "no member" error is more interesting

@l1storez
Copy link
Collaborator Author

l1storez commented Oct 27, 2021

I need help with import-error. I specified the correct path to the file, the tests are working but pylint gives an error

************* Module test_models
tests/test_models.py:9:0: E0401: Unable to import 'blog.models' (import-error)
************* Module test_views
tests/test_views.py:13:0: E0401: Unable to import 'blog.models' (import-error)

.pre-commit-config.yaml Outdated Show resolved Hide resolved
tests/models_test.py Outdated Show resolved Hide resolved
@webknjaz
Copy link
Member

I need help with import-error. I specified the correct path to the file, the tests are working but pylint gives an error

************* Module test_models
tests/test_models.py:9:0: E0401: Unable to import 'blog.models' (import-error)
************* Module test_views
tests/test_views.py:13:0: E0401: Unable to import 'blog.models' (import-error)

There's no such error in the CI. I only see no-member.

@l1storez
Copy link
Collaborator Author

There's no such error in the CI. I only see no-member.

Locally, I don't have no-member error, only import-error. no-member disappeared after 04ecaaf

@webknjaz
Copy link
Member

webknjaz commented Oct 28, 2021

This means that you run it differently or in a different env compared to the CI. Make sure to replicate the CI setup locally as close a possible.

@l1storez
Copy link
Collaborator Author

okay, I will try

@l1storez
Copy link
Collaborator Author

I find an interesting moment, when I run pre-commit run --all-files, I get:

************* Module test_models
tests/test_models.py:19:12: E1101: Class 'Post' has no 'objects' member (no-member)

************* Module test_views
tests/test_views.py:33:22: E1101: Class 'Post' has no 'objects' member (no-member)
tests/test_views.py:49:15: E1101: Class 'Post' has no 'objects' member (no-member)
tests/test_views.py:62:20: E1101: Class 'Post' has no 'objects' member (no-member)

but when I run git commit, I get:

************* Module test_models
tests/test_models.py:9:0: E0401: Unable to import 'blog.models' (import-error)
************* Module test_views
tests/test_views.py:13:0: E0401: Unable to import 'blog.models' (import-error)

I think I need to fix pre-commit check

@l1storez
Copy link
Collaborator Author

l1storez commented Nov 5, 2021

Add an no-member error to ignore?

@webknjaz
Copy link
Member

webknjaz commented Nov 5, 2021

No, try integrating the pylint-django plugin, it should take care of this problem.

@l1storez
Copy link
Collaborator Author

l1storez commented Nov 5, 2021

okay

@l1storez
Copy link
Collaborator Author

I pushed some updates to check pre-commit, cuz my local pre-commit setup broke after the system update

@@ -8,6 +8,7 @@ lazy-object-proxy==1.6.0
mccabe==0.6.1
psycopg2-binary==2.9.1
pylint==2.9.5
pylint-django==2.4.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to configure pylint to actually load this plugin. It is currently not used in your setup.

@webknjaz webknjaz closed this Aug 25, 2022
@webknjaz webknjaz reopened this Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants