2

I'm adding some performance smoke tests to our test suite, and they fail spectacularly when running py.test with coverage. This isn't very surprising, nor an indication of a performance issue (timings under coverage don't relate to anything real..)

How do I mark (ie. pytest.mark.skipif(..)) these tests so they're automatically skipped during coverage runs?

I'm using PyCharm during development if it is relevant.

1 Answer 1

1

That should be quite doable, using the pytest config object. See the very last example on Skip and xfail:

@pytest.mark.skipif(not pytest.config.getvalue("db"),
                    reason="--db was not specified")
def test_function(...):
    pass

I imagine what you want is just

@pytest.mark.skipif(pytest.config.getvalue("--cov"),
                    reason="--cov not compatible with smoke tests")

(ETA: The destination of cov is actually cov_source, which is why it didn't recognise cov. Putting --cov seems like a safer bet as it matches the option you actually type and doesn't require you to know the code internals.)

Sign up to request clarification or add additional context in comments.

7 Comments

If I call py.test --cov=. it gives me a ValueError: no option named 'cov' is there some other way I should specify coverage so it's picked up by config?
I guess you are not using pytest-cov then. What exact command is being run when you "run py.test with coverage"? I haven't used PyCharm but I imagine it has a console or log where you could find this out.
Yes, I'm using pytest-cov. I'll be happy if I can get this to work from the command line, i.e. py.test --cov=. tests where tests is the test folder. PyCharm uses C:\srv\venv\dkforms\Scripts\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 4.0.4\helpers\run_coverage.py" run "--omit=C:\Program Files (x86)\JetBrains\PyCharm 4.0.4\helpers*" "C:\Program Files (x86)\JetBrains\PyCharm 4.0.4\helpers\pycharm\pytestrunner.py" -p pytest_teamcity C:/srv/lib/dkforms/tests
OK I'm a bit confused, do you want to get this working in the command line or through PyCharm?
That ValueError suggests that your virtualenv is not set correctly when you run py.test on the command line, or the plugin is not being picked up.
|

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.