4

Is there a way to point pytest at a differnt pytest.ini file?

The application I am working on has one pytest.ini file that is used for running unittests when it spins up, and I do not want to modify that file.

I do however want to point pytest at a different file when running my automation tests via pytest.main()

pytest.main(['-p', 'no:django', '-v', '--json-report', '-m', test_marker])

Is there a way to tell pytest to use a pytest.ini file from another location?

Lombax
  • 851
  • 4
  • 9
  • 25
  • In addition to the answer: when in need of overriding values from `pytest.ini`, you can use `-o` arg, for example `pytest -o xfail_strict=1 -o junit_logging=no` etc. – hoefling Sep 13 '18 at 20:18

1 Answers1

8
$ pytest --help | grep -F config
  -c file               load configuration from `file` instead of trying to
                        locate one of the implicit configuration files.

That is,

pytest.main(['-c', 'pytest-alt.ini'])
phd
  • 82,685
  • 13
  • 120
  • 165