mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-27267: swap diff in pytest (Sync tcmessages and add test)
Actual and expected are in wrong order. Fixed on tcmessages side, test added. Use swapdiff in pytest.ini to switch it back
This commit is contained in:
@@ -25,7 +25,7 @@ from teamcity import diff_tools
|
||||
diff_tools.patch_unittest_diff()
|
||||
|
||||
|
||||
def fetch_diff_error_from_message(err_message):
|
||||
def fetch_diff_error_from_message(err_message, swap_diff):
|
||||
line_with_diff = None
|
||||
diff_error_message = None
|
||||
lines = err_message.split("\n")
|
||||
@@ -41,7 +41,11 @@ def fetch_diff_error_from_message(err_message):
|
||||
parts = [x.strip() for x in line_with_diff.split("==")]
|
||||
parts = [s[1:-1] if s.startswith("'") or s.startswith('"') else s for s in parts]
|
||||
# Pytest cuts too long lines, no need to check is_too_big
|
||||
return diff_tools.EqualsAssertionError(parts[0], parts[1], diff_error_message)
|
||||
expected, actual = parts[1], parts[0]
|
||||
|
||||
if swap_diff:
|
||||
expected, actual = actual, expected
|
||||
return diff_tools.EqualsAssertionError(expected, actual, diff_error_message)
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -71,6 +75,7 @@ def pytest_addoption(parser):
|
||||
kwargs.update({"type": "bool"})
|
||||
|
||||
parser.addini("skippassedoutput", **kwargs)
|
||||
parser.addini("swapdiff", **kwargs)
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
@@ -89,7 +94,8 @@ def pytest_configure(config):
|
||||
config._teamcityReporting = EchoTeamCityMessages(
|
||||
output_capture_enabled,
|
||||
coverage_controller,
|
||||
skip_passed_output
|
||||
skip_passed_output,
|
||||
bool(config.getini('swapdiff'))
|
||||
)
|
||||
config.pluginmanager.register(config._teamcityReporting)
|
||||
|
||||
@@ -110,7 +116,7 @@ def _get_coverage_controller(config):
|
||||
|
||||
|
||||
class EchoTeamCityMessages(object):
|
||||
def __init__(self, output_capture_enabled, coverage_controller, skip_passed_output):
|
||||
def __init__(self, output_capture_enabled, coverage_controller, skip_passed_output, swap_diff):
|
||||
self.coverage_controller = coverage_controller
|
||||
self.output_capture_enabled = output_capture_enabled
|
||||
self.skip_passed_output = skip_passed_output
|
||||
@@ -120,6 +126,7 @@ class EchoTeamCityMessages(object):
|
||||
|
||||
self.max_reported_output_size = 1 * 1024 * 1024
|
||||
self.reported_output_chunk_size = 50000
|
||||
self.swap_diff = swap_diff
|
||||
|
||||
def get_id_from_location(self, location):
|
||||
if type(location) is not tuple or len(location) != 3 or not hasattr(location[2], "startswith"):
|
||||
@@ -258,7 +265,7 @@ class EchoTeamCityMessages(object):
|
||||
if err_message.startswith("assert"):
|
||||
err_message = "AssertionError: " + err_message
|
||||
if err_message.startswith("AssertionError:"):
|
||||
diff_error = fetch_diff_error_from_message(err_message)
|
||||
diff_error = fetch_diff_error_from_message(err_message, self.swap_diff)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
def test_diff():
|
||||
assert "actual" == "expected"
|
||||
@@ -66,6 +66,32 @@ public final class PythonPyTestingTest extends PyEnvTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDiff() {
|
||||
runPythonTest(
|
||||
new PyProcessWithConsoleTestTask<PyTestTestProcessRunner>("/testRunner/env/pytest/diff", SdkCreationType.EMPTY_SDK) {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PyTestTestProcessRunner createProcessRunner() {
|
||||
return new PyTestTestProcessRunner("test_diff.py", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkTestResults(@NotNull final PyTestTestProcessRunner runner,
|
||||
@NotNull final String stdout,
|
||||
@NotNull final String stderr,
|
||||
@NotNull final String all) {
|
||||
|
||||
final String expectedConsoleText = "Expected :expected\n" +
|
||||
"Actual :actual\n" +
|
||||
" <Click to see difference>";
|
||||
Assert.assertThat("No diff", runner.getAllConsoleText(), Matchers.containsString(expectedConsoleText));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides existing .xml and checks that configuration is able to parse it
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user