'Ensure that the --liveserver option sets the environment variable
correctly.
Refs #2879.'

def test_liveserver(self):

    address_predefined = (u'DJANGO_LIVE_TEST_SERVER_ADDRESS' in os.environ)
    old_address = os.environ.get(u'DJANGO_LIVE_TEST_SERVER_ADDRESS')
    self.cmd.handle(verbosity=0, testrunner=u'admin_scripts.tests.CustomTestRunner')
    self.assertEqual((u'DJANGO_LIVE_TEST_SERVER_ADDRESS' in os.environ), address_predefined)
    self.assertEqual(os.environ.get(u'DJANGO_LIVE_TEST_SERVER_ADDRESS'), old_address)
    self.cmd.handle(verbosity=0, testrunner=u'admin_scripts.tests.CustomTestRunner', liveserver=u'blah')
    self.assertEqual(os.environ[u'DJANGO_LIVE_TEST_SERVER_ADDRESS'], u'blah')
    if address_predefined:
        os.environ[u'DJANGO_LIVE_TEST_SERVER_ADDRESS'] = old_address
    else:
        del os.environ[u'DJANGO_LIVE_TEST_SERVER_ADDRESS']
