Open jayvdb opened 7 years ago
I suspect it is failing on with .. as ..:
Can you please provide a minimal example and use context-diff. I can't spot what is changed here. Thanks.
The problem is that within
with self.assertRaisesRegex(SystemExit, '2') as cm:
the self.assertRaisesRegex(…)
gets expanded to
pytest.raises(SystemExit) as excinfo:
assert re.search(pattern, excinfo.value)
Easy As a quick solution we could do this when converting the code
with
-clauseHelp wanted: In the long-run:
with
-clauseas
-target name, if there is one, defaulting to excinfo
self.assertRaisesRegex(…)
onlyassert re.search(pattern, excinfo.value)
as first statement in the with
-blockas
-target given, issue a warning that the code still needs to be adjusted, since in the target's attributes are not compatible between unittest and pytest.
An enhance solution would be to try to determine if the target name is used within the with
-block and issue the warning only then. Wow, and the even enhanced version would be to try to rewrite the attribute access. Volunteers are very welcome :-)FWIW since 2.10
pytest.raises
as context-manager supports a match
keyword which matches with re.search
, so:
with self.assertRaisesRegex(SystemExit, '2') as cm:
Can be rewritten directly as:
with pytest.raises(SystemExit, match='2') as cm:
Using the match
keyword could be an elegant solution, but it would impose that any test-suite converted with unittest2pytest requires an up-to-date version of pytest.
I'm fine with this, since any project converting now ought not have "pinned" to a specific version of pytest. But we should be aware of this, decide about it and document.
For the records: Even if the docs say this was added in 2.10, the changelog says it was added in 3.1.0 (2017-05-22)
For the records: Even if the docs say this was added in 2.10, the changelog says it was added in 3.1.0 (2017-05-22)
Oops thanks for catching that, I will fix it in the docs. 👍
xref: pytest-dev/pytest#2697
The tool chokes on https://github.com/coala/coala/blob/8a25983/tests/parsing/CliParsingTest.py#L58
Somehow it writes
with
statements without a trailing:
.The result is naturally a syntax error: https://travis-ci.org/jayvdb/coala/jobs/246949584#L9068