Skip to content

2.8.2 - specific test not running if custom parameter is used #1183

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

Closed
novakmi opened this issue Nov 19, 2015 · 10 comments
Closed

2.8.2 - specific test not running if custom parameter is used #1183

novakmi opened this issue Nov 19, 2015 · 10 comments

Comments

@novakmi
Copy link

novakmi commented Nov 19, 2015

In pytest 2.8.2, when single test is specified with optional parameter, the test will not run.

Runs OK:

py.test -s -v t1/t1_test.py::TestT1::test_t1     

Does not run:

py.test -s -v t1/t1_test.py::TestT1::test_t1 --dry-run

error:

  usage: py.test [options] [file_or_dir] [file_or_dir] [...]
  py.test: error: unrecognized arguments: --dry-run
      inifile: <removed dir>/tmp/pytest/t1/setup.cfg
      rootdir: <removed dir>/tmp/pytest/t1

(--dry-run is custom parameter from conftest.py)

This scenario is working with pytest 2.7.3

The source code can be found here:
https://mega.nz/#!hR1ABCIT!lSLEoWMCOUn1pDziFSu0qxh3AMcLVuNtUA6FpRVh_Zs

to reproduce, unpack tgz and try steps above with pytest 2.8.2 (fails) and then with pytest 2.7.3 (OK)

Is this a pytest issue or something wrong in my test structure/parameter handling?

Thanks.

@RonnyPfannschmidt
Copy link
Member

please use a gist

@novakmi
Copy link
Author

novakmi commented Nov 19, 2015

I'm not sure if I can put full directory structure to the gist, so I have set-up new repository. Please can you
use:

git clone [email protected]:novakmi/pytest_param_issue_2_8_2.git

Thanks

@RonnyPfannschmidt
Copy link
Member

as far as i can tell this is related to changes on when deep conftests are considered
its suggested to use local plugins and addopts = -p myplugin

@novakmi
Copy link
Author

novakmi commented Nov 19, 2015

Not sure if I understand correctly, but I have only one conftest.py (top directory) file used to parse optional parameter (that I want to add to may tests). The rest is directory structure that specifies the tests (organized in the directories).
There is no plugin in the source code. It has something to do with optional parameter (in my case --dry-run) and full test specification. If I use -k test_t1 instead of the full test specification, it works fine:

   py.test -s -v  -k test_t1 --dry-run

If I need to use -p myplugin what would be the myplugin in my case?

Thanks

@RonnyPfannschmidt
Copy link
Member

the plugin would be a self-made python module with the addoption hook

@novakmi
Copy link
Author

novakmi commented Nov 20, 2015

I'm sorry, but I still do not understand.
I have tired to add directory:

./args/args.py
./args/init.py

(where args.py is same as original conftest.py)

running:
py.test -s -v t1/t1_test.py::TestT1::test_t1 --dry-run -p args

ends with

ImportError: No module named args

(not Python expert, so I guess I'm doing something wrong ;-) )

As I mentioned above, why is it necessary to make any module or plugin. The use case is:

  • tests are organized in the directories
  • custom option is used and handled in conftest.py (in the example --dry-run)
  • I would like to run just one specific test (ideally just by copy pasting from previous output with -v option - t1/t1_test.py::TestT1::test_t1 PASSED)
  • it most cases it is possible to use -k (e.g. -k test_t1, but not all the time, as it may match more than one test)

Yes, it looks like that when specific test is in a subdirectory, the topmost conftest.py is not processed. When I copy the test file out of the subdirectory (t1 - from the example), it works:

  py.test -v t1_test.py::TestT1::test_t1 --dry-run
  t1_test.py::TestT1::test_t1 PASSED

vs

  py.test -v t1/t1_test.py::TestT1::test_t1 --dry-run
  py.test: error: unrecognized arguments: --dry-run

Thanks.

@novakmi
Copy link
Author

novakmi commented Nov 20, 2015

After investigation, I have found workaround:

       py.test -v t1/t1_test.py::TestT1::test_t1 --confcutdir . --dry-run

Still have feeling something is broken. The use case from previous message seems quite obvious scenario (run specific test in directory and use custom option specified in top conftest.py) and was working just fine in 2.7.x.

@blueyed
Copy link
Contributor

blueyed commented Jun 21, 2016

@novakmi

Yes, it looks like that when specific test is in a subdirectory, the topmost conftest.py is not processed.

That's because the rootdir is being detected as t1 because of the setup.cfg file therein (https://github.com/novakmi/pytest_param_issue_2_8_2/blob/master/t1/setup.cfg)!

You should be able to work around this by using:

py.test -v -c conftest.py t1/t1_test.py::TestT1::test_t1 --dry-run

But then the question also is why you have two setup.cfg files, and that these should probably be just merged (into the one next to conftest.py).

It would be great if you could provide feedback on the documentation / behavior change/fixes at #1621.

@novakmi
Copy link
Author

novakmi commented Jun 25, 2016

Hello, thanks for the reply. Yes, removing setup.cfg from t1 directory helps. The only reason I have it in t1 is/was to keep markers and options related to t1 tests in the t1 directory (in my real project, not in this example). In this way, if I delete t1 directory, I do not need to modify topmost setup.cfg.

suggested
py.test -v -c conftest.py t1/t1_test.py::TestT1::test_t1 --dry-run
fails i my environment (seem like import statements make problem)

py._iniconfig.ParseError: conftest.py:1: unexpected line: 'import ConfigParser'

I can use --confcutdir=. option and I will consider removing setup.cfg from subdirectories.

(from my view issue can be closed as I understand now new behavior of rootdir discovery)

@nicoddemus
Copy link
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants