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

Testing: run Coverage report only on CircleCI #10611

Merged
merged 2 commits into from Aug 10, 2023
Merged

Conversation

humitos
Copy link
Member

@humitos humitos commented Aug 8, 2023

I've been hitting an issue while debugging test cases that it doesn't stop exactly where I put the breakpoint. This has been pretty annoying since I'm in the middle of an inner function and I have to do multiple steps forward to find the exact place where I put my breakpoint.

Today I found this problem is due to an incompatibility of pytest-cov and the debuggers: https://pytest-cov.readthedocs.io/en/latest/debuggers.html.

@humitos humitos requested a review from a team as a code owner August 8, 2023 13:36
@humitos humitos requested a review from stsewd August 8, 2023 13:36
@humitos
Copy link
Member Author

humitos commented Aug 8, 2023

Take a look at this example:

diff --git a/readthedocs/rtd_tests/tests/test_profile_views.py b/readthedocs/rtd_tests/tests/test_profile_views.py
index 42298cde2..fb99c597f 100644
--- a/readthedocs/rtd_tests/tests/test_profile_views.py
+++ b/readthedocs/rtd_tests/tests/test_profile_views.py
@@ -37,6 +37,7 @@ class ProfileViewsTest(TestCase):
         )
         self.assertTrue(resp.status_code, 200)
 
+        import pdb; pdb.set_trace()
         self.user.refresh_from_db()
         self.user.profile.refresh_from_db()
         self.assertEqual(self.user.first_name, 'Read')

Running the tests using coverage

When it stops, I'm inside refresh_from_db 🤷🏼

root@ce473d3604cd:/usr/src/app/checkouts/readthedocs.org# tox -e py310 -- --nomigrations -k test_edit_profile
py310: commands[0]> sh -c 'export DJANGO_SETTINGS_MODULE=readthedocs.settings.test; pytest --cov-report=xml --cov-config .coveragerc --cov=. --pyargs readthedocs --suppress-no-test-exit-code -m "not proxito and not embed_api" --nomigrations -k test_edit_profile'

...

readthedocs/rtd_tests/tests/test_profile_views.py 

...

--Call--
> /usr/src/app/checkouts/readthedocs.org/.tox/py310/lib/python3.10/site-packages/django/db/models/base.py(607)refresh_from_db()
-> def refresh_from_db(self, using=None, fields=None):
(Pdb) l
602  	       return {
603  	           f.attname for f in self._meta.concrete_fields
604  	           if f.attname not in self.__dict__
605  	       }
606  	
607  ->	   def refresh_from_db(self, using=None, fields=None):
608  	       """
609  	       Reload field values from the database.
610  	
611  	       By default, the reloading happens from the database this instance was
612  	       loaded from, or by the read router if this instance wasn't loaded from
(Pdb)

Running tests without using coverage (this PR)

I'm stopped exactly where I put the pdb 💯

root@ce473d3604cd:/usr/src/app/checkouts/readthedocs.org# tox -e py310 -- --nomigrations -k test_edit_profile
py310: commands[0]> sh -c 'export DJANGO_SETTINGS_MODULE=readthedocs.settings.test; pytest --pyargs readthedocs --suppress-no-test-exit-code -m "not proxito and not embed_api" --nomigrations -k test_edit_profile'

....

readthedocs/rtd_tests/tests/test_profile_views.py 

...

> /usr/src/app/checkouts/readthedocs.org/readthedocs/rtd_tests/tests/test_profile_views.py(41)test_edit_profile()
-> self.user.refresh_from_db()
(Pdb) l
 36  	           },
 37  	       )
 38  	       self.assertTrue(resp.status_code, 200)
 39  	
 40  	       import pdb; pdb.set_trace()
 41  ->	       self.user.refresh_from_db()
 42  	       self.user.profile.refresh_from_db()
 43  	       self.assertEqual(self.user.first_name, 'Read')
 44  	       self.assertEqual(self.user.last_name, 'Docs')
 45  	       self.assertEqual(self.user.profile.homepage, 'readthedocs.org')
 46  	
(Pdb)

Copy link
Member

@stsewd stsewd left a comment

Choose a reason for hiding this comment

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

I'm -1 on removing our coverage. We should use it more instead of removing it.
Conditionally running coverage could be supported with an env var or similar {env:COVERAGEOFF:--cov-report=xml...}.

@humitos
Copy link
Member Author

humitos commented Aug 9, 2023

I like the idea of using an env variable to decide whether or not run it. I will update this PR to run it by default only on CircleCI

@humitos humitos requested a review from stsewd August 9, 2023 08:23
@humitos humitos changed the title Testing: remove Coverage report due to issue with Python debugger Testing: run Coverage report only on CircleCI Aug 9, 2023
I've been hitting an issue while debugging test cases that it doesn't stop
exactly where I put the breakpoint. This has been pretty annoying since I'm in
the middle of an inner function and I have to do multiple steps forward to find
the exact place where I put my breakpoint.

Today I found this problem is due to an incompatibility of `pytest-cov` and the
debuggers: https://pytest-cov.readthedocs.io/en/latest/debuggers.html.
.circleci/config.yml Outdated Show resolved Hide resolved
@humitos humitos requested a review from stsewd August 10, 2023 09:41
@humitos humitos merged commit 797dcc6 into main Aug 10, 2023
7 checks passed
@humitos humitos deleted the humitos/remove-pytest-cov branch August 10, 2023 14:51
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.

None yet

2 participants