I have some python code and a bunch of pytest tests for it.
Some of the tests I expect to fail (that is, I am testing error handling, so I pass in inputs that should cause my code to throw exceptions.)
In order to do this, I have code like this:
CF_TESTDATA =[('data/1_input.csv', 'data/1_input.csv', 'utf-8'),
pytest.mark.xfail(('data/1_input_unknown_encoding.txt', '', 'utf-8')),
('data/1_input_macintosh.txt', 'data/1_converted_macroman.csv', 'macroman')]
@pytest.mark.parametrize('input_file, expected_output, encoding', CF_TESTDATA)
def test_convert_file(testdir, tmpdir, input_file, expected_output, encoding):
'''
Test the function that converts a file to UTF-8.
'''
...
The idea here is that the second run of this test, with input_file = 'data/1_input_unknown_encoding.txt', I expect the code under test to fail.
This seems to work fine, and when I run from the command line, pytest tells me that the test has xfailed. I can follow the code in the debugger and see that it is throwing the expected exception. So that's all well and good.
But Jenkins is showing this test as skkipped. When I look at the output I see the message:
Skip Message
expected test failure
Why does the test show as skipped? It seems like the test runs, and fails as expected. That's not the same as the test being skipped.
Aucun commentaire:
Enregistrer un commentaire