2

I am trying to integrate pytest-jira plugin to my python script. I am referring to this link.

It is not feasible to hard code username/password in clear text form in ~/jira.cfg. Is there any way I can override them from outside? Basically I am looking for ways to skip hard coding of password in jira.cfg.

username = USERNAME (or blank for no authentication
password = PASSWORD (or blank for no authentication)

Can someone suggest a way to do this?

npatel
  • 1,081
  • 2
  • 13
  • 21
  • 2
    according to the readme in the pytest-jira repository, you can put `jira.cfg` somewhere else. that doesn't get around the apparent plain-text requirement. You could always engineer some additional solution to get the username and password from an external source and create the `jira.cfg` file dynamically. – sam Mar 22 '18 at 19:26

1 Answers1

2

You can simply overwrite the arguments by defining your own pytest_configure hook. That's the beauty of pytest: you can redefine almost everything and adapt it to your particular needs. Example with reading username/password from environment variables:

# conftest.py

import os
import pytest


def pytest_configure(config):
    username = os.getenv('JIRA_USER', None)
    password = os.getenv('JIRA_PASSWORD', None)
    if username and password:
        config.option.jira_username = username
        config.option.jira_password = password

That's it! Test it:

$ export JIRA_USER=me JIRA_PASSWORD=mypass
$ pytest --jira
hoefling
  • 59,418
  • 12
  • 147
  • 194