Skip to content

Running tests generated by pytest_generate_tests with the -k flag fails. #2479

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
darshakkakkad opened this issue Jun 7, 2017 · 4 comments
Closed
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@darshakkakkad
Copy link

I am generating testmethod names using pytest_generate_tests and then executing them with the keyword substring match (-k flag).

Simplified Example:

test_data = [
    {
        "application" : "foo",
        "page" : "foo_page"
    },
    {
        "application" : "bar",
        "page" : "bar_page"
    }
]

def pytest_generate_tests(metafunc):
    metafunc.parametrize("test_data", test_data)

def test_bug(param):
    assert 1 == 1

2 tests with the following names are generated - test_bug[test_data0] and test_bug[test_data1]

Error:
When I run these with pytest -k "test_bug[test_data0] or test_bug[test_data1]", I get a TypeError: 'bool' object is not subscriptable.

Code:
https://github.com/pytest-dev/pytest/blob/master/_pytest/mark.py#L215-L220

My Reason why it fails:
As I have 2 tests and none of them start with the not keyword, the execution comes to L#220 (return eval(keywordexpr, {}, mapping))
eval() thinks the keywordexpr string provided contains a dictionary with test_bug as the dictionary name and test_data0 & test_data1 as the dictionary keys.
So, it matches test_bug with the mapping. This step returns a bool.
Now, it tries to access the key test_data0 on this bool (True[test_data0] | False[test_data0]) at which place it complains saying TypeError: 'bool' object is not subscriptable.

If I run pytest -k "test_bug[test_data0]", it works fine because L215-L216 gets executed.

If I run pytest -k "test_bug1 or test_bug2", it works fine.

If I run pytest -k "test_bug[test_data0] ", it fails.

Versions
OS version: OSX Sierra, Win7
Pytest version: pytest-2.6.4
Python Version: 3.4.4, 3.5.2

Does this appear to be an issue when using pytest_generate_tests and the -k flag together? Is this a known issue)? Any suggestions would be appreciated.

Thanks,
Darshak

@darshakkakkad
Copy link
Author

Would anyone have any ideas?

@RonnyPfannschmidt
Copy link
Member

RonnyPfannschmidt commented Jun 27, 2017

@darshakkakkad without testing i suggest to try py.test -k "test_bug and ( test_data0 or test_data1)"

@RonnyPfannschmidt RonnyPfannschmidt added the type: question general question, might be closed after 2 weeks of inactivity label Jun 27, 2017
@RonnyPfannschmidt
Copy link
Member

also #1141 is related

@nicoddemus
Copy link
Member

Closing as this has not seen activity in awhile, and there's a related issue already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants