SebastianM6L,
@SebastianM6L@mastodon.social avatar

Anyone had an issue with from django.test import Client causing a high memory usage in a docker container?

I run the tests in a pipeline using a #jenkins agent in #docker.

When this test runs:

def test_login_user(self):  
 c = Client()  
 response = c.post('/user/login/', {'email': 'test1@test.de', 'password': 'test123'})  
self.assertEqual(response.status_code, 302)  

The memory usage goes thru the roof. Literally using up all memory until it crashes.

#django #pytest

ghickman,
@ghickman@mastodon.social avatar

@SebastianM6L Client runs a the full request stack, could a piece of middleware be causing you problems? Does the memory problem happen at import? Instantiation? When calling post()?

SebastianM6L,
@SebastianM6L@mastodon.social avatar

@ghickman It seems to happen on the instantiation of client().

It get's even more strange. I just tried and ran the tests with python manage.py test and it went thru.

Seems to be caused somehow by pytest.
django-pytest is installed.

ghickman,
@ghickman@mastodon.social avatar

@SebastianM6L I’m on mobile atm so can’t check but IIRC pytest-django is doing some config for you, setting the settings var, etc. but I didnt think there were any auto run fixtures by default 🤔 could you be using different settings between the two test runners?

SebastianM6L,
@SebastianM6L@mastodon.social avatar

@ghickman The settings are the same.

The Jenkins agent runs Python 3.12 and this happens with pytest 3.1.1 as well as 3.2.0.

On my MacBook I run Python 3.9 and there is no issue with pytest 3.1.1.

Could it be somehow an issue with python 3.12?

ghickman,
@ghickman@mastodon.social avatar

@SebastianM6L could be 🤔 I’d certainly want to copy the CI env as closely as possible! Can you check env vars in CI vs your local setup too?

SebastianM6L,
@SebastianM6L@mastodon.social avatar

@ghickman After a bit of testing, I can narrow the error down being an issue with python 3.12.
Running the tests locally on my mac with python 3.12 results in same error.
When I downgrade python to 3.11 the tests run normally.

The question is now where to create an issue. Is it pytest-django, pytest, django or even python?

SebastianM6L,
@SebastianM6L@mastodon.social avatar

@ghickman Ok could further distill it down. The issue seems to be with the cov plugin.
Removinb addopts = --cov from the pytest.ini file solved the issue.

ghickman,
@ghickman@mastodon.social avatar

@SebastianM6L ooh something changed with coverage in 3.12 IIRC, possibly something to do with how it collects data? You could also try running coverage without the Pytest plugin, to see if the wrapper is involved?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • jenkins
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines