Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 241085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:43:25+00:00 2026-05-11T20:43:25+00:00

I want to write a unit test that performs HTTP requests directly (instead of

  • 0

I want to write a unit test that performs HTTP requests directly (instead of using django.test.client.Client).

If you’re curious why – it’s because I want to test a Thrift-over-HTTP API that I expose from my Django application – and I want to use the Thrift client in the unit test.

The problem is that during tests, the server is not actually being run. When using django.test.client.Client, it will simply call the view functions instead of actually making a HTTP request. (Please correct me if I’m wrong.)

So what would be the best way to force the test framework to start the HTTP server?

I tried writing a bash script that does something like this:

./manage.py testserver --addrport 7000 &
PID=$!
sleep 5
./manage.py test --no-input
kill $PID

But that is messy (and doesn’t really work) because 1) I need the sleep (otherwise the test will start before the DB is initialized by the test server) and 2) the test will try to initialize the database again (after the testserver already initialized it).

Any other solutions to this?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:43:25+00:00Added an answer on May 11, 2026 at 8:43 pm

    Yup, you’re right – it’s a problem and there is a bug for it: http://code.djangoproject.com/ticket/2879

    Just, you might then encounter multithreaded problems, intentionally ommited: http://code.djangoproject.com/ticket/10117 http://code.djangoproject.com/ticket/4513 http://code.djangoproject.com/ticket/3357

    I am frustrated, thus I wrote a library that includes starting live server in separate thread and cleaning it afterwards: http://devel.almad.net/trac/django-sane-testing/ . It also starts Django’s server multithreaded by runtime monkeypatching and you can use cherrypy http instead (which is better anyway).

    Only problem is it requires you to use nose as test framework (100% backward compatibility with standard unittest, but if you’re already using something else…). You can then just use –with-django and –with-djangoliveserver/–with-cherrypyliveserver. No idea how it will work with thrift.

    Just beware:

    • Please do not bug Django devs with bugreports, you’re on your own
    • Windmill provides same solution, so if you’re using windmill, you’ll probably have port conflicts
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer imageSet = [NSArray arrayWithObjects:img, img1, img2, img3, img4, img5, img,… May 12, 2026 at 12:44 am
  • Editorial Team
    Editorial Team added an answer An article with some code: you just need a call… May 12, 2026 at 12:43 am
  • Editorial Team
    Editorial Team added an answer Let's make sure we cover the basics here: Do you… May 12, 2026 at 12:43 am

Related Questions

I have some C# unit tests that perform some float/double operations and I would
I have a pseudo random number generator (PRNG) class that I want to unit
I'm new to build automation and Continuous Integration, but have done extensive research on
Hy, I'm writing a class which should help me in unit tests. The class

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.