Always show full comparison output if on CI.
When you don't get enough information with a test running on a CI, it's quite frustrating, for various reasons: - It's more likely to be a flaky test, so you might not be able to reproduce the failure. - Passing -vv is quite bothersome (creating a temporary commit and reverting it) For those reasons, if something goes wrong on CI, it's good to have as much information as possible.
This commit is contained in:
		
							parent
							
								
									eebf5c1d2c
								
							
						
					
					
						commit
						3e5c9038ec
					
				|  | @ -26,6 +26,10 @@ | ||||||
|   including removal of the obsolete ``_pytest.assertion.oldinterpret`` module. |   including removal of the obsolete ``_pytest.assertion.oldinterpret`` module. | ||||||
|   Thanks `@nicoddemus`_ for the PR (`#1226`_). |   Thanks `@nicoddemus`_ for the PR (`#1226`_). | ||||||
| 
 | 
 | ||||||
|  | * Comparisons now always show up in full when ``CI`` or ``BUILD_NUMBER`` is | ||||||
|  |   found in the environment, even when -vv isn't used. | ||||||
|  |   Thanks `@The-Compiler`_ for the PR. | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| **Bug Fixes** | **Bug Fixes** | ||||||
| 
 | 
 | ||||||
|  | @ -44,6 +48,7 @@ | ||||||
| .. _@jab: https://github.com/jab | .. _@jab: https://github.com/jab | ||||||
| .. _@codewarrior0: https://github.com/codewarrior0 | .. _@codewarrior0: https://github.com/codewarrior0 | ||||||
| .. _@jaraco: https://github.com/jaraco | .. _@jaraco: https://github.com/jaraco | ||||||
|  | .. _@The-Compiler: https://github.com/The-Compiler | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 2.8.6.dev1 | 2.8.6.dev1 | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ | ||||||
| support for presenting detailed information in failing assertions. | support for presenting detailed information in failing assertions. | ||||||
| """ | """ | ||||||
| import py | import py | ||||||
|  | import os | ||||||
| import sys | import sys | ||||||
| from _pytest.monkeypatch import monkeypatch | from _pytest.monkeypatch import monkeypatch | ||||||
| from _pytest.assertion import util | from _pytest.assertion import util | ||||||
|  | @ -86,6 +87,12 @@ def pytest_collection(session): | ||||||
|         hook.set_session(session) |         hook.set_session(session) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | def _running_on_ci(): | ||||||
|  |     """Check if we're currently running on a CI system.""" | ||||||
|  |     env_vars = ['CI', 'BUILD_NUMBER'] | ||||||
|  |     return any(var in os.environ for var in env_vars) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def pytest_runtest_setup(item): | def pytest_runtest_setup(item): | ||||||
|     """Setup the pytest_assertrepr_compare hook |     """Setup the pytest_assertrepr_compare hook | ||||||
| 
 | 
 | ||||||
|  | @ -99,7 +106,8 @@ def pytest_runtest_setup(item): | ||||||
| 
 | 
 | ||||||
|         This uses the first result from the hook and then ensures the |         This uses the first result from the hook and then ensures the | ||||||
|         following: |         following: | ||||||
|         * Overly verbose explanations are dropped unles -vv was used. |         * Overly verbose explanations are dropped unless -vv was used or | ||||||
|  |           running on a CI. | ||||||
|         * Embedded newlines are escaped to help util.format_explanation() |         * Embedded newlines are escaped to help util.format_explanation() | ||||||
|           later. |           later. | ||||||
|         * If the rewrite mode is used embedded %-characters are replaced |         * If the rewrite mode is used embedded %-characters are replaced | ||||||
|  | @ -113,7 +121,8 @@ def pytest_runtest_setup(item): | ||||||
|         for new_expl in hook_result: |         for new_expl in hook_result: | ||||||
|             if new_expl: |             if new_expl: | ||||||
|                 if (sum(len(p) for p in new_expl[1:]) > 80*8 |                 if (sum(len(p) for p in new_expl[1:]) > 80*8 | ||||||
|                         and item.config.option.verbose < 2): |                         and item.config.option.verbose < 2 | ||||||
|  |                         and not _running_on_ci()): | ||||||
|                     show_max = 10 |                     show_max = 10 | ||||||
|                     truncated_lines = len(new_expl) - show_max |                     truncated_lines = len(new_expl) - show_max | ||||||
|                     new_expl[show_max:] = [py.builtin._totext( |                     new_expl[show_max:] = [py.builtin._totext( | ||||||
|  |  | ||||||
|  | @ -405,7 +405,7 @@ def test_sequence_comparison_uses_repr(testdir): | ||||||
|     ]) |     ]) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_assert_compare_truncate_longmessage(testdir): | def test_assert_compare_truncate_longmessage(monkeypatch, testdir): | ||||||
|     testdir.makepyfile(r""" |     testdir.makepyfile(r""" | ||||||
|         def test_long(): |         def test_long(): | ||||||
|             a = list(range(200)) |             a = list(range(200)) | ||||||
|  | @ -414,6 +414,7 @@ def test_assert_compare_truncate_longmessage(testdir): | ||||||
|             b = '\n'.join(map(str, b)) |             b = '\n'.join(map(str, b)) | ||||||
|             assert a == b |             assert a == b | ||||||
|     """) |     """) | ||||||
|  |     monkeypatch.delenv('CI', raising=False) | ||||||
| 
 | 
 | ||||||
|     result = testdir.runpytest() |     result = testdir.runpytest() | ||||||
|     # without -vv, truncate the message showing a few diff lines only |     # without -vv, truncate the message showing a few diff lines only | ||||||
|  | @ -431,6 +432,12 @@ def test_assert_compare_truncate_longmessage(testdir): | ||||||
|         "*- 197", |         "*- 197", | ||||||
|     ]) |     ]) | ||||||
| 
 | 
 | ||||||
|  |     monkeypatch.setenv('CI', '1') | ||||||
|  |     result = testdir.runpytest() | ||||||
|  |     result.stdout.fnmatch_lines([ | ||||||
|  |         "*- 197", | ||||||
|  |     ]) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def test_assertrepr_loaded_per_dir(testdir): | def test_assertrepr_loaded_per_dir(testdir): | ||||||
|     testdir.makepyfile(test_base=['def test_base(): assert 1 == 2']) |     testdir.makepyfile(test_base=['def test_base(): assert 1 == 2']) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue