简体   繁体   中英

Django/Travis CI - configuring a .travis YAML file to first start a localhost server, then run my tests without hanging?

I'm starting to setup a CI environment for one of my (first) Django projects. I'm having trouble with travis; when I test my code locally, I first have to run 'manage.py runserver' to start my server; then I can run my unit tests with 'manage.py tests.' So in my .travis.yml file, I have it start the server first, then run the unit tests, then run the integration tests (which are in a self-made python script). My main problem is that this causes travis to hang: it starts the server and then waits for input. Which is expected; the documentation, which I've pored through all day, says that it will error out a build if it receives no output for longer than ten minutes. How would I set up my .travis file to start the localhost server, THEN keep it running and move on to the integration tests? Unit tests are fine, I can run them without spinning up the server of course, but I need the server running to pass my integration tests; the only test I've written so far starts off with an assert to check if 'Django' is the page's title. This fails without the server of course. Any help would be appreciated..I know the code's technically fine since this whole problem is due to me not being able to configure the .travis.yml file correctly and therefore not letting travis run my tests on it's own instance of a localhost, but after searching for hours and getting my fifth or sixth email about failed builds on my dev branch I got irritated. Travis file: http://pastebin.com/U0GpnF5y

So silly me, after fighting for almost two days straight I figured it out. Dead simple answer and I feel stupid but I'll post it here just in case someone else who doesn't do more than simple stuff with the linux shell stumbles upon it.
I appended an ampersand to the end of the python manage.py runserver line (I'm assuming this tells the os to run this as a separate job, or to run it and proceed to the next task) and kept it in the before_script section. So the end of the .yml file looks like:

before_script:
  python manage.py runserver &

script:
  coverage run manage.py tests
  coverage run functional_tests.py

after_script:
  coveralls

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM