1

In tests directory has 2 sub-directories such as tests/api and tests/sanity. Note tests/api has conftest.py that expects to find input.conf in tests/api directory. Note running tests from tests/api works fine. But run test from parent directory tests, it failed with: py.test --test_option=input.conf Usage: py.test [options] [file_or_dir] [file_or_dir] [...]

py.test: error: no such option: --test_option

Can someone please shows how I can structure my test so this would work? I also tried specify the test directory such as the following but it cannot find input.conf. py.test --test_option=input.conf api/test_api.py

E IOError: [Errno 2] No such file or directory: 'input.conf'

1 Answer 1

1

Assuming that your syntax is correct (you are I think transposing the name and extension of the file) you just need to specify the location of the file correctly including relative or absolute path:

Instead of:

py.test --test_option=input.conf

do:

py.test --test_option=api/input.conf 
Sign up to request clarification or add additional context in comments.

2 Comments

Great. This worked. py.test --test_option=api/input.conf api/test_api.py .One follow up question is if I have multiple directories that contains tests and each one has their own input.conf file and I want to run all of them. Is this possible?
Yes, but you need to change a program a little bit. Take a look at these file/directory functions docs.python.org/library/os.html#files-and-directories and accept the answer if you are happy with it (or ask as many Python questions as you wish :-) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.