I have a Django and Django REST app, and when I run my unit testing locally, every test runs and passes. However, when I create a GitHub Action to run my unit testing, 6 of my unit tests failure with the following message:
File "/opt/hostedtoolcache/Python/3.9.5/x64/lib/python3.9/urllib/parse.py", line 178, in port
raise ValueError(message) from None
ValueError: Port could not be cast to integer value as 'None'
Here is my Action:
django-test-lint:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.3-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: github_actions
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: psycopg2 prerequisites
run: sudo apt-get install libpq-dev
- name: Run migrations
run: python app/manage.py migrate
- name: Run tests and lint with coverage
run: |
cd app
coverage erase
coverage run manage.py test && flake8
coverage report -m
The impression I get, is this happens with these 6 tests when it is trying to send a post, patch, or delete to my endpoints. It's like Github Actions can't fine my container host when running my Django RF app. Maybe it's something to do with my allowed hosts. I've tried many configs in my settings.py, but nothing is working. Here is my current settings around allowed hosts, have I got something wrong?
if os.environ.get('GITHUB_WORKFLOW'):
ALLOWED_HOSTS = os.getenv('DJANGO_ALLOWED_HOSTS', '127.0.0.1').split(',')
else:
ALLOWED_HOSTS = [os.environ.get('HOST_IP'), '127.0.0.1', 'localhost']
Whilst the whole Django-test-lint job completes, I get theses errors and therefore no longer get 100% coverage on my unit tests.