Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a command line argument is a directory that contains a tox.ini file, that tox file is used #4009

Closed
MattSable opened this issue Sep 20, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@MattSable
Copy link

commented Sep 20, 2018

If you supply a command line argument that is a directory that contains a tox.ini file, that tox file gets used. Example layout and files that can reproduce this:

/tests
    conftest.py
    test.py
/some_folder
    tox.ini

conftest.py

def pytest_addoption(parser):
    parser.addoption(
        "--foo"
    )

test.py

def test():
    print("Hello world!")

tox.ini

[pytest]
addopts = --collect-only

Running just pytest .\tests\test.py, I get the expected output:

============================= test session starts =============================
platform win32 -- Python 3.6.4, pytest-3.8.0, py-1.6.0, pluggy-0.7.1
rootdir: C:\Users\masable\Desktop\examples, inifile:
collected 1 item

tests\test.py .                                                          [100%]

========================== 1 passed in 0.03 seconds ===========================

If instead you run pytest .\tests\test.py --foo .\some_folder\, than the tox.ini in some_folder is used, and the output is:

============================= test session starts =============================
platform win32 -- Python 3.6.4, pytest-3.8.0, py-1.6.0, pluggy-0.7.1
rootdir: C:\Users\masable\Desktop\examples\some_folder, inifile: tox.ini
collected 1 item
<Module 'test.py'>
  <Function 'test'>

======================== no tests ran in 0.02 seconds =========================

I'm on pytest 3.8.0.

@nicoddemus

This comment has been minimized.

Copy link
Member

commented Sep 20, 2018

Unfortunately that's a problem with the args parser: by the time it is figuring out the command-line, it doesn't know yet that conftest.py will create a --foo option, so it assumes .\some_folder is a directory to look for tests.

A workaround is to use --foo=.\some_folder instead.

Unfortunately this is not easy to fix because the parser at that time doesn't know yet about --foo. I think this might be related to #1149.

@Zac-HD

This comment has been minimized.

Copy link
Member

commented Jun 25, 2019

I believe this is closed by #5469.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.