test_python_flask.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. from tests.package.test_python import TestPythonPackageBase
  2. import os
  3. import time
  4. class TestPythonPy3Flask(TestPythonPackageBase):
  5. __test__ = True
  6. config = TestPythonPackageBase.config + \
  7. """
  8. BR2_PACKAGE_PYTHON3=y
  9. BR2_PACKAGE_PYTHON_FLASK=y
  10. """
  11. sample_scripts = ["tests/package/sample_python_flask.py"]
  12. timeout = 60
  13. def test_run(self):
  14. self.login()
  15. self.check_sample_scripts_exist()
  16. cmd = "FLASK_APP=%s %s -m flask run > /dev/null 2>&1 &" % (os.path.basename(self.sample_scripts[0]),
  17. self.interpreter)
  18. _, exit_code = self.emulator.run(cmd, timeout=self.timeout)
  19. # Give enough time for the flask server to start up
  20. for attempt in range(30):
  21. time.sleep(1)
  22. cmd = "wget -q -O - http://127.0.0.1:5000/"
  23. output, exit_code = self.emulator.run(cmd, timeout=self.timeout)
  24. if exit_code == 0:
  25. self.assertEqual(output[0], 'Hello, World!')
  26. break
  27. else:
  28. self.assertTrue(False, "Timeout while waiting for flask server")