Hi, I’m having trouble getting CircleCI config.yml to handle four command line arguments that my code sets through os.getenv as environment variables. I’m guessing that CircleCI can’t read the os.getenv addopts from the code and so flags the arguments as unrecognized.
While setting the os.getenv addopts as environment variables in CircleCI may allow them to get recognized, I don’t want to set the values there when I add them. The values need to be set at the command line.
Everything works as expected locally, and through Jenkins, but for a number of reasons we’re trying to move away from Jenkins.
Here is the error:
[percy] Running "pytest src/tests/test_percy_static.py -v --baseurl=https://[redacted] --auth=https://[redacted]@[redacted] --site=4WP-US --env=UAT3"
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --baseurl= --auth= --site= --env= --baseurl=https://[redacted] --auth=[redacted]@[redacted] --site=4WP-US --env=UAT3
inifile: /home/circleci/project/src/tests/pytest.ini
rootdir: /home/circleci/project/src/tests
Exited with code exit status 4
CircleCI received exit code 4
Here is the config.yml:
version: 2.1
parameters:
baseurl:
type: string
default: https://[redacted]
auth:
type: string
default: https://[redacted]@[redacted]
site:
type: string
default: 4WP-US
env:
type: string
default: UAT3
orbs:
python: circleci/python@2.0.3
browser-tools: circleci/browser-tools@1.1
jobs:
run_tests:
docker:
- image: cimg/python:3.9-browsers
environment:
PYTHONPATH: /home/circleci/percy_ui/src
steps:
- checkout
- browser-tools/install-chrome
- browser-tools/install-chromedriver
- run:
name: Check Installations
command: |
python --version
node --version
google-chrome --version
chromedriver --version
- restore_cache:
key: depsV1-{{ checksum "requirements.txt" }}
- run:
name: Install Dependencies via requirements.txt file
command: |
pip install -r requirements.txt
- save_cache:
paths:
- ""
key: depsV1-{{ checksum "requirements.txt" }}
- run:
name: Check Pytest Installation
command: |
pytest --version
- run:
name: Install Percy CLI & Run Tests
command: |
sudo npm install -g --save-dev @percy/cli
sudo chmod -R 777 /usr/local/lib/node_modules/@percy/cli/node_modules/@percy/core/
echo 'export PERCY_TOKEN=${PERCY_TOKEN}' >> $BASH_ENV; source $BASH_ENV;
percy exec -- pytest src/tests/test_percy_static.py -v --baseurl=<< pipeline.parameters.baseurl >> --auth=<< pipeline.parameters.auth >> --site=<< pipeline.parameters.site >> --env=<< pipeline.parameters.env >>
workflows:
build_test:
jobs:
- run_tests
And here are the relevant contents of conftest.py:
def pytest_addoption(parser):
parser.addoption("--baseurl", action='store', default='https://[redacted]')
parser.addoption("--auth", action='store', default='https://[redacted]@[redacted]')
parser.addoption("--site", action='store', default='4WP-US')
parser.addoption("--env", action='store', default='UAT3')
def pytest_configure(config):
os.environ['baseurl'] = config.getoption('baseurl')
os.environ['auth'] = config.getoption('auth')
os.environ['site'] = config.getoption('site')
os.environ['env'] = config.getoption('env')
Obviously I’m new to CircleCI and trying to get this off the ground. So far I’ve been unable to find anything in the documentation that helps with this specific use case.