dimanche 11 juin 2017

Wait for stdout on Popen

I am trying to setting up an acceptance test harness for a flask app and I am currently struggling to wait for the app to start before making calls.

Following construct works fine:

class SpinUpTests(unittest.TestCase):
def tearDown(self):
    super().tearDown()
    self.stubby_server.kill()
    self.stubby_server.communicate()

def test_given_not_yet_running_when_created_without_config_then_started_on_default_port(self):
    self.not_yet_running(5000)

    self.stubby_server = subprocess.Popen(['python', '../../app/StubbyServer.py'], stdout=subprocess.PIPE)
    time.sleep(1)#<--- I would like to get rid of this

    self.then_started_on_port(5000)

I would like to wait on stdout for:

self.stubby_server = subprocess.Popen(['python', '../../app/StubbyServer.py'], stdout=subprocess.PIPE) time.sleep(1)#<--- I would like to get rid of this

I tried

for line in self.stubby_server.stdout.readline()

but readline() never finishes, tho I already see the output in the test output window.

Any ideas how I can wait for the flask app to start without having to use an explicit sleep()?

1 commentaire:

  1. Selenium Training Course


    Amazing, thanks a lot my friend, I was also siting like a your banner image when I was thrown into Selenium.When I started learning then I understood it has got really cool stuff.
    I can vouch webdriver has proved the best feature in Selenium framework.
    Thanks a lot for taking a time to share a wonderful article.


    Selenium Training in Velachery

    RépondreSupprimer