Dataset Viewer
Auto-converted to Parquet
repo
string
instance_id
string
html_url
string
feature_patch
string
test_patch
string
doc_changes
list
version
string
base_commit
string
PASS2PASS
list
FAIL2PASS
list
mask_doc_diff
list
augmentations
dict
problem_statement
string
psf/requests
psf__requests-5856
https://github.com/psf/requests/pull/5856
diff --git a/HISTORY.md b/HISTORY.md index 59e4a9f707..ccf4e17400 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,7 +4,12 @@ Release History dev --- -- \[Short description of non-trivial change.\] +- \[Short description of non-trivial change.\] + +- Added a `requests.exceptions.JSONDecodeError` to decrease inconsistencies + in the library. This gets raised in the `response.json()` method, and is + backwards compatible as it inherits from previously thrown exceptions. + Can be caught from `requests.exceptions.RequestException` as well. 2.26.0 (2021-07-13) ------------------- diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index b4649f00d5..73d0b2931a 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -153,9 +153,9 @@ There's also a builtin JSON decoder, in case you're dealing with JSON data:: In case the JSON decoding fails, ``r.json()`` raises an exception. For example, if the response gets a 204 (No Content), or if the response contains invalid JSON, -attempting ``r.json()`` raises ``simplejson.JSONDecodeError`` if simplejson is -installed or raises ``ValueError: No JSON object could be decoded`` on Python 2 or -``json.JSONDecodeError`` on Python 3. +attempting ``r.json()`` raises ``requests.exceptions.JSONDecodeError``. This wrapper exception +provides interoperability for multiple exceptions that may be thrown by different +python versions and json serialization libraries. It should be noted that the success of the call to ``r.json()`` does **not** indicate the success of the response. Some servers may return a JSON object in a diff --git a/requests/__init__.py b/requests/__init__.py index 0ac7713b81..53a5b42af6 100644 --- a/requests/__init__.py +++ b/requests/__init__.py @@ -139,7 +139,7 @@ def _check_cryptography(cryptography_version): from .exceptions import ( RequestException, Timeout, URLRequired, TooManyRedirects, HTTPError, ConnectionError, - FileModeWarning, ConnectTimeout, ReadTimeout + FileModeWarning, ConnectTimeout, ReadTimeout, JSONDecodeError ) # Set default logging handler to avoid "No handler found" warnings. diff --git a/requests/compat.py b/requests/compat.py index 0b14f5015c..029ae62ac3 100644 --- a/requests/compat.py +++ b/requests/compat.py @@ -28,8 +28,10 @@ #: Python 3.x? is_py3 = (_ver[0] == 3) +has_simplejson = False try: import simplejson as json + has_simplejson = True except ImportError: import json @@ -49,13 +51,13 @@ # Keep OrderedDict for backwards compatibility. from collections import Callable, Mapping, MutableMapping, OrderedDict - builtin_str = str bytes = str str = unicode basestring = basestring numeric_types = (int, long, float) integer_types = (int, long) + JSONDecodeError = ValueError elif is_py3: from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag @@ -66,6 +68,10 @@ # Keep OrderedDict for backwards compatibility. from collections import OrderedDict from collections.abc import Callable, Mapping, MutableMapping + if has_simplejson: + from simplejson import JSONDecodeError + else: + from json import JSONDecodeError builtin_str = str str = str diff --git a/requests/exceptions.py b/requests/exceptions.py index c412ec9868..957e31f384 100644 --- a/requests/exceptions.py +++ b/requests/exceptions.py @@ -8,6 +8,8 @@ """ from urllib3.exceptions import HTTPError as BaseHTTPError +from .compat import JSONDecodeError as CompatJSONDecodeError + class RequestException(IOError): """There was an ambiguous exception that occurred while handling your @@ -29,6 +31,10 @@ class InvalidJSONError(RequestException): """A JSON error occurred.""" +class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError): + """Couldn't decode the text into json""" + + class HTTPError(RequestException): """An HTTP error occurred.""" diff --git a/requests/models.py b/requests/models.py index aa6fb86e4e..e7d292d580 100644 --- a/requests/models.py +++ b/requests/models.py @@ -29,7 +29,9 @@ from .cookies import cookiejar_from_dict, get_cookie_header, _copy_cookie_jar from .exceptions import ( HTTPError, MissingSchema, InvalidURL, ChunkedEncodingError, - ContentDecodingError, ConnectionError, StreamConsumedError, InvalidJSONError) + ContentDecodingError, ConnectionError, StreamConsumedError, + InvalidJSONError) +from .exceptions import JSONDecodeError as RequestsJSONDecodeError from ._internal_utils import to_native_string, unicode_is_ascii from .utils import ( guess_filename, get_auth_from_url, requote_uri, @@ -38,7 +40,7 @@ from .compat import ( Callable, Mapping, cookielib, urlunparse, urlsplit, urlencode, str, bytes, - is_py2, chardet, builtin_str, basestring) + is_py2, chardet, builtin_str, basestring, JSONDecodeError) from .compat import json as complexjson from .status_codes import codes @@ -468,9 +470,9 @@ def prepare_body(self, data, files, json=None): content_type = 'application/json' try: - body = complexjson.dumps(json, allow_nan=False) + body = complexjson.dumps(json, allow_nan=False) except ValueError as ve: - raise InvalidJSONError(ve, request=self) + raise InvalidJSONError(ve, request=self) if not isinstance(body, bytes): body = body.encode('utf-8') @@ -882,12 +884,8 @@ def json(self, **kwargs): r"""Returns the json-encoded content of a response, if any. :param \*\*kwargs: Optional arguments that ``json.loads`` takes. - :raises simplejson.JSONDecodeError: If the response body does not - contain valid json and simplejson is installed. - :raises json.JSONDecodeError: If the response body does not contain - valid json and simplejson is not installed on Python 3. - :raises ValueError: If the response body does not contain valid - json and simplejson is not installed on Python 2. + :raises requests.exceptions.JSONDecodeError: If the response body does not + contain valid json. """ if not self.encoding and self.content and len(self.content) > 3: @@ -907,7 +905,16 @@ def json(self, **kwargs): # and the server didn't bother to tell us what codec *was* # used. pass - return complexjson.loads(self.text, **kwargs) + + try: + return complexjson.loads(self.text, **kwargs) + except JSONDecodeError as e: + # Catch JSON-related errors and raise as requests.JSONDecodeError + # This aliases json.JSONDecodeError and simplejson.JSONDecodeError + if is_py2: # e is a ValueError + raise RequestsJSONDecodeError(e.message) + else: + raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) @property def links(self):
diff --git a/tests/test_requests.py b/tests/test_requests.py index b77cba007d..b6d97dd9f4 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -2570,4 +2570,9 @@ def test_parameters_for_nonstandard_schemes(self, input, params, expected): def test_post_json_nan(self, httpbin): data = {"foo": float("nan")} with pytest.raises(requests.exceptions.InvalidJSONError): - r = requests.post(httpbin('post'), json=data) \ No newline at end of file + r = requests.post(httpbin('post'), json=data) + + def test_json_decode_compatibility(self, httpbin): + r = requests.get(httpbin('bytes/20')) + with pytest.raises(requests.exceptions.JSONDecodeError): + r.json() \ No newline at end of file
[ { "path": "docs/user/quickstart.rst", "old_path": "a/docs/user/quickstart.rst", "new_path": "b/docs/user/quickstart.rst", "metadata": "diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst\nindex b4649f00d5..73d0b2931a 100644\n--- a/docs/user/quickstart.rst\n+++ b/docs/user/quickstart.rst\n@@ -153,9 +153,9 @@ There's also a builtin JSON decoder, in case you're dealing with JSON data::\n \n In case the JSON decoding fails, ``r.json()`` raises an exception. For example, if\n the response gets a 204 (No Content), or if the response contains invalid JSON,\n-attempting ``r.json()`` raises ``simplejson.JSONDecodeError`` if simplejson is\n-installed or raises ``ValueError: No JSON object could be decoded`` on Python 2 or\n-``json.JSONDecodeError`` on Python 3.\n+attempting ``r.json()`` raises ``requests.exceptions.JSONDecodeError``. This wrapper exception\n+provides interoperability for multiple exceptions that may be thrown by different\n+python versions and json serialization libraries.\n \n It should be noted that the success of the call to ``r.json()`` does **not**\n indicate the success of the response. Some servers may return a JSON object in a\n", "update": null } ]
2.26
a1a6a549a0143d9b32717dbe3d75cd543ae5a4f6
[ "tests/test_requests.py::TestRequests::test_invalid_url[InvalidSchema-localhost.localdomain:3128/]", "tests/test_requests.py::TestRequests::test_params_bytes_are_encoded", "tests/test_requests.py::TestTimeout::test_invalid_timeout[foo-must be an int, float or None]", "tests/test_requests.py::TestRequests::test_basicauth_with_netrc", "tests/test_requests.py::test_data_argument_accepts_tuples[data0]", "tests/test_requests.py::TestRequests::test_basic_building", "tests/test_requests.py::TestRequests::test_set_basicauth[user-pass]", "tests/test_requests.py::TestRequests::test_set_basicauth[None-None]", "tests/test_requests.py::TestRequests::test_unicode_multipart_post[data2]", "tests/test_requests.py::TestTimeout::test_invalid_timeout[timeout0-(connect, read)]", "tests/test_requests.py::TestRequests::test_HTTP_302_ALLOW_REDIRECT_GET", "tests/test_requests.py::TestRequests::test_set_basicauth[42-42]", "tests/test_requests.py::TestRequests::test_transfer_enc_removal_on_redirect", "tests/test_requests.py::TestRequests::test_basic_auth_str_is_always_native[test-test-Basic dGVzdDp0ZXN0]", "tests/test_requests.py::TestPreparingURLs::test_preparing_bad_url[http://*.google.com0]", "tests/test_requests.py::TestRequests::test_http_302_doesnt_change_head_to_get", "tests/test_requests.py::TestRequests::test_set_cookie_on_301", "tests/test_requests.py::TestCaseInsensitiveDict::test_init[cid2]", "tests/test_requests.py::TestCaseInsensitiveDict::test_copy", "tests/test_requests.py::TestRequests::test_header_no_return_chars", "tests/test_requests.py::TestRequests::test_no_content_length[HEAD]", "tests/test_requests.py::TestRequests::test_cookie_sent_on_redirect", "tests/test_requests.py::TestPreparingURLs::test_preparing_bad_url[http://*1]", "tests/test_requests.py::TestRequests::test_auth_is_retained_for_redirect_on_host", "tests/test_requests.py::TestRequests::test_HTTP_200_OK_GET_WITH_PARAMS", "tests/test_requests.py::TestRequests::test_requests_in_history_are_not_overridden", "tests/test_requests.py::TestCaseInsensitiveDict::test_update_retains_unchanged", "tests/test_requests.py::TestPreparingURLs::test_preparing_url[http://\\u30b8\\u30a7\\u30fc\\u30d4\\u30fc\\u30cb\\u30c3\\u30af.jp-http://xn--hckqz9bzb1cyrb.jp/]", "tests/test_requests.py::TestRequests::test_header_and_body_removal_on_redirect", "tests/test_requests.py::TestRequests::test_request_ok_set", "tests/test_requests.py::TestRequests::test_respect_proxy_env_on_request", "tests/test_requests.py::TestRequests::test_links", "tests/test_requests.py::TestRequests::test_POSTBIN_GET_POST_FILES_WITH_DATA", "tests/test_requests.py::TestRequests::test_fixes_1329", "tests/test_requests.py::TestRequests::test_DIGEST_HTTP_200_OK_GET", "tests/test_requests.py::TestRequests::test_params_are_merged_case_sensitive", "tests/test_requests.py::TestRequests::test_response_json_when_content_is_None", "tests/test_requests.py::TestCaseInsensitiveDict::test_get", "tests/test_requests.py::TestCaseInsensitiveDict::test_setdefault", "tests/test_requests.py::TestRequests::test_empty_response_has_content_none", "tests/test_requests.py::TestRequests::test_empty_content_length[PATCH]", "tests/test_requests.py::TestMorselToCookieExpires::test_expires_none", "tests/test_requests.py::TestRequests::test_proxy_auth_empty_pass", "tests/test_requests.py::TestCaseInsensitiveDict::test_iter", "tests/test_requests.py::TestPreparingURLs::test_preparing_url[http://xn--n3h.net/-http://xn--n3h.net/0]", "tests/test_requests.py::TestPreparingURLs::test_url_mutation[http+unix://%2Fvar%2Frun%2Fsocket/path%7E-http+unix://%2Fvar%2Frun%2Fsocket/path~1]", "tests/test_requests.py::TestCaseInsensitiveDict::test_update", "tests/test_requests.py::TestRequests::test_cookie_parameters", "tests/test_requests.py::TestRequests::test_DIGESTAUTH_WRONG_HTTP_401_GET", "tests/test_requests.py::TestRequests::test_no_body_content_length[POST]", "tests/test_requests.py::TestRequests::test_generic_cookiejar_works", "tests/test_requests.py::TestRequests::test_certificate_failure", "tests/test_requests.py::TestRequests::test_invalid_url[InvalidSchema-10.122.1.1:3128/]", "tests/test_requests.py::TestRequests::test_manual_redirect_with_partial_body_read", "tests/test_requests.py::TestRequests::test_respect_proxy_env_on_send_with_redirects", "tests/test_requests.py::TestRequests::test_non_prepared_request_error", "tests/test_requests.py::TestRequests::test_should_strip_auth_http_downgrade", "tests/test_requests.py::TestRequests::test_user_agent_transfers[User-agent]", "tests/test_requests.py::TestRequests::test_cookie_as_dict_keys", "tests/test_requests.py::TestPreparingURLs::test_url_mutation[http+unix://%2Fvar%2Frun%2Fsocket/path%7E-http+unix://%2Fvar%2Frun%2Fsocket/path~0]", "tests/test_requests.py::TestRequests::test_response_chunk_size_type", "tests/test_requests.py::TestRequests::test_params_original_order_is_preserved_by_default", "tests/test_requests.py::TestRequests::test_can_send_objects_with_files[foo0]", "tests/test_requests.py::TestRequests::test_response_context_manager", "tests/test_requests.py::test_data_argument_accepts_tuples[data1]", "tests/test_requests.py::test_prepared_copy[kwargs3]", "tests/test_requests.py::TestRequests::test_params_are_added_before_fragment[http://example.com/path#fragment-http://example.com/path?a=b#fragment]", "tests/test_requests.py::TestRequests::test_unicode_get[\\xf8-params4]", "tests/test_requests.py::TestRequests::test_basicauth_encodes_byte_strings", "tests/test_requests.py::TestPreparingURLs::test_url_mutation[data:SSDimaUgUHl0aG9uIQ==-data:SSDimaUgUHl0aG9uIQ==]", "tests/test_requests.py::TestRequests::test_chunked_upload_does_not_set_content_length_header", "tests/test_requests.py::TestRequests::test_http_303_changes_post_to_get", "tests/test_requests.py::TestRequests::test_history_is_always_a_list", "tests/test_requests.py::TestCaseInsensitiveDict::test_lower_items", "tests/test_requests.py::TestRequests::test_mixed_case_scheme_acceptable[http://]", "tests/test_requests.py::test_proxy_env_vars_override_default[https_proxy-https://example.com-socks5://proxy.com:9876]", "tests/test_requests.py::TestRequests::test_HTTP_200_OK_GET_WITH_MIXED_PARAMS", "tests/test_requests.py::TestRequests::test_HTTP_307_ALLOW_REDIRECT_POST_WITH_SEEKABLE", "tests/test_requests.py::TestRequests::test_unicode_method_name_with_request_object", "tests/test_requests.py::TestTimeout::test_read_timeout[timeout0]", "tests/test_requests.py::TestRequests::test_mixed_case_scheme_acceptable[hTTp://]", "tests/test_requests.py::TestRequests::test_unicode_header_name", "tests/test_requests.py::TestRequests::test_conflicting_post_params", "tests/test_requests.py::TestRequests::test_rewind_body_failed_tell", "tests/test_requests.py::test_json_encodes_as_bytes", "tests/test_requests.py::TestPreparingURLs::test_url_mutation[mailto:user@example.org-mailto:user@example.org0]", "tests/test_requests.py::TestRequests::test_cookie_as_dict_keeps_len", "tests/test_requests.py::TestRequests::test_HTTP_200_OK_HEAD", "tests/test_requests.py::TestRequests::test_BASICAUTH_TUPLE_HTTP_200_OK_GET", "tests/test_requests.py::TestCaseInsensitiveDict::test_preserve_last_key_case", "tests/test_requests.py::TestRequests::test_cookie_policy_copy", "tests/test_requests.py::TestRequests::test_can_send_objects_with_files[foo1]", "tests/test_requests.py::TestRequests::test_empty_content_length[PUT]", "tests/test_requests.py::TestRequests::test_response_decode_unicode", "tests/test_requests.py::TestRequests::test_header_value_not_str", "tests/test_requests.py::TestRequests::test_http_error", "tests/test_requests.py::TestRequests::test_cookie_duplicate_names_raises_cookie_conflict_error", "tests/test_requests.py::TestRequests::test_transport_adapter_ordering", "tests/test_requests.py::TestRequests::test_unicode_get[/get-params2]", "tests/test_requests.py::TestRequests::test_mixed_case_scheme_acceptable[HttP://]", "tests/test_requests.py::TestPreparingURLs::test_preparing_url[http://\\xe3\\x82\\xb8\\xe3\\x82\\xa7\\xe3\\x83\\xbc\\xe3\\x83\\x94\\xe3\\x83\\xbc\\xe3\\x83\\x8b\\xe3\\x83\\x83\\xe3\\x82\\xaf.jp-http://xn--hckqz9bzb1cyrb.jp/]", "tests/test_requests.py::TestRequests::test_no_body_content_length[OPTIONS]", "tests/test_requests.py::TestPreparingURLs::test_post_json_nan", "tests/test_requests.py::TestTimeout::test_encoded_methods", "tests/test_requests.py::TestRequests::test_prepared_request_hook", "tests/test_requests.py::TestCaseInsensitiveDict::test_equality", "tests/test_requests.py::TestMorselToCookieExpires::test_expires_invalid_int[100-TypeError]", "tests/test_requests.py::TestRequests::test_params_are_added_before_fragment[http://example.com/path?key=value#fragment-http://example.com/path?key=value&a=b#fragment]", "tests/test_requests.py::TestRequests::test_response_is_iterable", "tests/test_requests.py::TestRequests::test_rewind_body_failed_seek", "tests/test_requests.py::TestRequests::test_long_authinfo_in_url", "tests/test_requests.py::TestRequests::test_path_is_not_double_encoded", "tests/test_requests.py::TestRequests::test_HTTP_302_TOO_MANY_REDIRECTS", "tests/test_requests.py::test_proxy_env_vars_override_default[http_proxy-http://example.com-socks5://proxy.com:9876]", "tests/test_requests.py::TestPreparingURLs::test_preparing_url[http://[1200:0000:ab00:1234:0000:2552:7777:1313]:12345/-http://[1200:0000:ab00:1234:0000:2552:7777:1313]:12345/1]", "tests/test_requests.py::TestRequests::test_invalid_ca_certificate_path", "tests/test_requests.py::TestRequests::test_session_hooks_are_overridden_by_request_hooks", "tests/test_requests.py::TestRequests::test_DIGEST_AUTH_RETURNS_COOKIE", "tests/test_requests.py::TestRequests::test_unicode_multipart_post[data3]", "tests/test_requests.py::TestRequests::test_whitespaces_are_removed_from_url", "tests/test_requests.py::TestTimeout::test_read_timeout[timeout1]", "tests/test_requests.py::TestRequests::test_user_agent_transfers[user-agent]", "tests/test_requests.py::TestMorselToCookieExpires::test_expires_invalid_int[woops-ValueError]", "tests/test_requests.py::TestRequests::test_cookielib_cookiejar_on_redirect", "tests/test_requests.py::test_requests_are_updated_each_time", "tests/test_requests.py::TestRequests::test_response_iter_lines", "tests/test_requests.py::TestRequests::test_unicode_multipart_post[data1]", "tests/test_requests.py::TestRequests::test_should_strip_auth_default_port[https://example.com/foo-https://example.com:443/bar]", "tests/test_requests.py::TestRequests::test_respect_proxy_env_on_send_self_prepared_request", "tests/test_requests.py::TestRequests::test_param_cookiejar_works", "tests/test_requests.py::TestPreparingURLs::test_preparing_url[http://stra\\xdfe.de/stra\\xdfe-http://xn--strae-oqa.de/stra%C3%9Fe]", "tests/test_requests.py::TestRequests::test_request_and_response_are_pickleable", "tests/test_requests.py::TestRequests::test_proxy_error", "tests/test_requests.py::TestRequests::test_DIGEST_AUTH_SETS_SESSION_COOKIES", "tests/test_requests.py::TestRequests::test_prepare_request_with_bytestring_url", "tests/test_requests.py::TestRequests::test_prepared_request_is_pickleable", "tests/test_requests.py::TestRequests::test_session_pickling", "tests/test_requests.py::TestRequests::test_unconsumed_session_response_closes_connection", "tests/test_requests.py::TestRequests::test_binary_put", "tests/test_requests.py::TestRequests::test_uppercase_scheme_redirect", "tests/test_requests.py::TestRequests::test_post_with_custom_mapping", "tests/test_requests.py::TestPreparingURLs::test_preparing_url[http://google.com-http://google.com/]", "tests/test_requests.py::TestRequests::test_no_body_content_length[PUT]", "tests/test_requests.py::TestRequests::test_invalid_url[InvalidURL-http://]", "tests/test_requests.py::TestRequests::test_POSTBIN_SEEKED_OBJECT_WITH_NO_ITER", "tests/test_requests.py::TestRequests::test_POSTBIN_GET_POST_FILES", "tests/test_requests.py::TestPreparingURLs::test_url_mutation[mailto:user@example.org-mailto:user@example.org1]", "tests/test_requests.py::TestRequests::test_should_strip_auth_port_change", "tests/test_requests.py::TestRequests::test_set_basicauth[\\xd0\\xb8\\xd0\\xbc\\xd1\\x8f-\\xd0\\xbf\\xd0\\xb0\\xd1\\x80\\xd0\\xbe\\xd0\\xbb\\xd1\\x8c]", "tests/test_requests.py::TestRequests::test_proxy_auth", "tests/test_requests.py::TestRequests::test_auth_is_stripped_on_http_downgrade", "tests/test_requests.py::TestRequests::test_fragment_maintained_on_redirect", "tests/test_requests.py::TestRequests::test_cookie_as_dict_values", "tests/test_requests.py::TestRequests::test_entry_points", "tests/test_requests.py::TestRequests::test_invalid_url[MissingSchema-hiwpefhipowhefopw]", "tests/test_requests.py::TestRequests::test_rewind_partially_read_body", "tests/test_requests.py::TestRequests::test_http_302_changes_post_to_get", "tests/test_requests.py::TestRequests::test_custom_redirect_mixin", "tests/test_requests.py::TestTimeout::test_none_timeout[timeout1]", "tests/test_requests.py::TestRequests::test_stream_with_auth_does_not_set_transfer_encoding_header", "tests/test_requests.py::TestRequests::test_invalid_files_input", "tests/test_requests.py::TestRequests::test_DIGEST_STREAM", "tests/test_requests.py::TestRequests::test_unicode_get[/get-params3]", "tests/test_requests.py::TestTimeout::test_none_timeout[None]", "tests/test_requests.py::TestCaseInsensitiveDict::test_fixes_649", "tests/test_requests.py::TestRequests::test_empty_content_length[OPTIONS]", "tests/test_requests.py::TestRequests::test_custom_content_type", "tests/test_requests.py::TestPreparingURLs::test_preparing_url[http://K\\xf6nigsg\\xe4\\xdfchen.de/stra\\xdfe-http://xn--knigsgchen-b4a3dun.de/stra%C3%9Fe]", "tests/test_requests.py::TestRequests::test_redirect_with_wrong_gzipped_header", "tests/test_requests.py::TestCaseInsensitiveDict::test_contains", "tests/test_requests.py::TestRequests::test_respect_proxy_env_on_get", "tests/test_requests.py::TestMorselToCookieMaxAge::test_max_age_invalid_str", "tests/test_requests.py::TestPreparingURLs::test_preparing_bad_url[http://\\u2603.net/]", "tests/test_requests.py::TestRequests::test_basic_auth_str_is_always_native[\\xd0\\xb8\\xd0\\xbc\\xd1\\x8f-\\xd0\\xbf\\xd0\\xb0\\xd1\\x80\\xd0\\xbe\\xd0\\xbb\\xd1\\x8c-Basic 0LjQvNGPOtC/0LDRgNC+0LvRjA==]", "tests/test_requests.py::TestTimeout::test_stream_timeout", "tests/test_requests.py::TestRequests::test_session_get_adapter_prefix_matching", "tests/test_requests.py::TestRequests::test_should_strip_auth_default_port[https://example.com:443/foo-https://example.com/bar]", "tests/test_requests.py::TestCaseInsensitiveDict::test_len", "tests/test_requests.py::TestRequests::test_proxy_error_on_bad_url", "tests/test_requests.py::TestRequests::test_header_keys_are_native", "tests/test_requests.py::TestRequests::test_pyopenssl_redirect", "tests/test_requests.py::TestRequests::test_unicode_multipart_post[data0]", "tests/test_requests.py::TestRequests::test_empty_content_length[POST]", "tests/test_requests.py::TestRequests::test_http_301_changes_post_to_get", "tests/test_requests.py::TestRequests::test_cookie_quote_wrapped", "tests/test_requests.py::TestRequests::test_cookie_as_dict_items", "tests/test_requests.py::TestRequests::test_request_cookies_not_persisted", "tests/test_requests.py::TestRequests::test_override_content_length", "tests/test_requests.py::TestRequests::test_no_content_length[GET]", "tests/test_requests.py::TestRequests::test_invalid_ssl_certificate_files", "tests/test_requests.py::TestRequests::test_HTTP_302_TOO_MANY_REDIRECTS_WITH_PARAMS", "tests/test_requests.py::TestPreparingURLs::test_preparing_url[http://stra\\xc3\\x9fe.de/stra\\xc3\\x9fe-http://xn--strae-oqa.de/stra%C3%9Fe]", "tests/test_requests.py::TestRequests::test_status_raising", "tests/test_requests.py::TestCaseInsensitiveDict::test_preserve_key_case", "tests/test_requests.py::TestRequests::test_prepared_request_with_hook_is_pickleable", "tests/test_requests.py::TestRequests::test_unicode_get[/get-params0]", "tests/test_requests.py::TestRequests::test_https_warnings", "tests/test_requests.py::TestRequests::test_should_strip_auth_default_port[http://example.com/foo-http://example.com:80/bar]", "tests/test_requests.py::TestRequests::test_prepared_request_with_file_is_pickleable", "tests/test_requests.py::TestPreparingURLs::test_preparing_url[http://K\\xc3\\xb6nigsg\\xc3\\xa4\\xc3\\x9fchen.de/stra\\xc3\\x9fe-http://xn--knigsgchen-b4a3dun.de/stra%C3%9Fe]", "tests/test_requests.py::TestRequests::test_unicode_multipart_post_fieldnames", "tests/test_requests.py::TestRequests::test_decompress_gzip", "tests/test_requests.py::TestRequests::test_HTTP_200_OK_GET_ALTERNATIVE", "tests/test_requests.py::TestRequests::test_mixed_case_scheme_acceptable[HTTP://]", "tests/test_requests.py::TestRequests::test_json_param_post_content_type_works", "tests/test_requests.py::TestRequests::test_unicode_method_name", "tests/test_requests.py::TestRequests::test_hook_receives_request_arguments", "tests/test_requests.py::TestRequests::test_response_without_release_conn", "tests/test_requests.py::TestRequests::test_session_get_adapter_prefix_matching_is_case_insensitive", "tests/test_requests.py::TestRequests::test_prepare_body_position_non_stream", "tests/test_requests.py::TestCaseInsensitiveDict::test_init[cid0]", "tests/test_requests.py::TestCaseInsensitiveDict::test_docstring_example", "tests/test_requests.py::TestRequests::test_cookie_duplicate_names_different_domains", "tests/test_requests.py::TestPreparingURLs::test_parameters_for_nonstandard_schemes[http+unix://%2Fvar%2Frun%2Fsocket/path-params0-http+unix://%2Fvar%2Frun%2Fsocket/path?key=value]", "tests/test_requests.py::TestRequests::test_http_with_certificate", "tests/test_requests.py::TestRequests::test_rewind_body_no_seek", "tests/test_requests.py::TestRequests::test_requests_history_is_saved", "tests/test_requests.py::TestCaseInsensitiveDict::test_init[cid1]", "tests/test_requests.py::TestPreparingURLs::test_preparing_url[http://[1200:0000:ab00:1234:0000:2552:7777:1313]:12345/-http://[1200:0000:ab00:1234:0000:2552:7777:1313]:12345/0]", "tests/test_requests.py::test_prepared_copy[None]", "tests/test_requests.py::TestRequests::test_header_no_leading_space", "tests/test_requests.py::TestRequests::test_response_reason_unicode_fallback", "tests/test_requests.py::TestRequests::test_headers_preserve_order", "tests/test_requests.py::TestPreparingURLs::test_preparing_url[http://xn--n3h.net/-http://xn--n3h.net/1]", "tests/test_requests.py::TestRequests::test_respect_proxy_env_on_send_session_prepared_request", "tests/test_requests.py::TestRequests::test_autoset_header_values_are_native", "tests/test_requests.py::TestCaseInsensitiveDict::test_delitem", "tests/test_requests.py::TestRequests::test_session_hooks_are_used_with_no_request_hooks", "tests/test_requests.py::TestRequests::test_rewind_body", "tests/test_requests.py::TestRequests::test_should_strip_auth_https_upgrade", "tests/test_requests.py::TestRequests::test_should_strip_auth_default_port[http://example.com:80/foo-http://example.com/bar]", "tests/test_requests.py::test_data_argument_accepts_tuples[data2]", "tests/test_requests.py::TestRequests::test_cannot_send_unprepared_requests", "tests/test_requests.py::TestRequests::test_session_close_proxy_clear", "tests/test_requests.py::TestMorselToCookieExpires::test_expires_valid_str", "tests/test_requests.py::TestRequests::test_header_remove_is_case_insensitive", "tests/test_requests.py::TestRequests::test_HTTP_307_ALLOW_REDIRECT_POST", "tests/test_requests.py::TestRequests::test_form_encoded_post_query_multivalued_element", "tests/test_requests.py::TestRequests::test_cookie_removed_on_expire", "tests/test_requests.py::test_prepared_copy[kwargs2]", "tests/test_requests.py::TestPreparingURLs::test_parameters_for_nonstandard_schemes[mailto:user@example.org-params2-mailto:user@example.org]", "tests/test_requests.py::TestRequests::test_no_body_content_length[PATCH]", "tests/test_requests.py::TestRequests::test_empty_stream_with_auth_does_not_set_content_length_header", "tests/test_requests.py::TestPreparingURLs::test_parameters_for_nonstandard_schemes[http+unix://%2Fvar%2Frun%2Fsocket/path-params1-http+unix://%2Fvar%2Frun%2Fsocket/path?key=value]", "tests/test_requests.py::TestMorselToCookieMaxAge::test_max_age_valid_int", "tests/test_requests.py::TestRequests::test_DIGESTAUTH_QUOTES_QOP_VALUE", "tests/test_requests.py::TestRequests::test_request_cookie_overrides_session_cookie", "tests/test_requests.py::TestPreparingURLs::test_preparing_bad_url[http://*.google.com1]", "tests/test_requests.py::TestRequests::test_different_encodings_dont_break_post", "tests/test_requests.py::TestRequests::test_urlencoded_get_query_multivalued_param", "tests/test_requests.py::TestRequests::test_can_send_objects_with_files[files2]", "tests/test_requests.py::test_urllib3_retries", "tests/test_requests.py::TestRequests::test_time_elapsed_blank", "tests/test_requests.py::TestPreparingURLs::test_parameters_for_nonstandard_schemes[mailto:user@example.org-params3-mailto:user@example.org]", "tests/test_requests.py::TestRequests::test_HTTP_200_OK_PUT", "tests/test_requests.py::TestRequests::test_nonhttp_schemes_dont_check_URLs", "tests/test_requests.py::TestRequests::test_invalid_url[InvalidSchema-localhost:3128]", "tests/test_requests.py::TestRequests::test_prepared_from_session", "tests/test_requests.py::TestPreparingURLs::test_preparing_bad_url[http://*0]", "tests/test_requests.py::TestRequests::test_cookie_persists_via_api", "tests/test_requests.py::TestRequests::test_can_send_file_object_with_non_string_filename", "tests/test_requests.py::TestRequests::test_should_strip_auth_host_change", "tests/test_requests.py::test_urllib3_pool_connection_closed", "tests/test_requests.py::TestRequests::test_http_303_doesnt_change_head_to_get", "tests/test_requests.py::TestRequests::test_json_param_post_should_not_override_data_param", "tests/test_requests.py::test_prepared_copy[kwargs1]", "tests/test_requests.py::TestCaseInsensitiveDict::test_getitem", "tests/test_requests.py::TestRequests::test_response_reason_unicode", "tests/test_requests.py::TestRequests::test_unicode_get[/get-params1]", "tests/test_requests.py::TestRequests::test_session_get_adapter_prefix_matching_mixed_case", "tests/test_requests.py::TestRequests::test_http_301_doesnt_change_head_to_get", "tests/test_requests.py::TestRequests::test_headers_on_session_with_None_are_not_sent", "tests/test_requests.py::TestRequests::test_cookie_as_dict_keeps_items", "tests/test_requests.py::TestRequests::test_header_validation" ]
[ "tests/test_requests.py::TestPreparingURLs::test_json_decode_compatibility" ]
[ { "path": "docs/user/quickstart.rst", "old_path": "a/docs/user/quickstart.rst", "new_path": "b/docs/user/quickstart.rst", "metadata": "diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst\nindex b4649f00..73d0b293 100644\n--- a/docs/user/quickstart.rst\n+++ b/docs/user/quickstart.rst\n@@ -153,9 +153,9 @@ There's also a builtin JSON decoder, in case you're dealing with JSON data::\n \n In case the JSON decoding fails, ``r.json()`` raises an exception. For example, if\n the response gets a 204 (No Content), or if the response contains invalid JSON,\n-attempting ``r.json()`` raises ``simplejson.JSONDecodeError`` if simplejson is\n-installed or raises ``ValueError: No JSON object could be decoded`` on Python 2 or\n-``json.JSONDecodeError`` on Python 3.\n+attempting ``r.json()`` raises ``requests.exceptions.JSONDecodeError``. This wrapper exception\n+provides interoperability for multiple exceptions that may be thrown by different\n+python versions and json serialization libraries.\n \n It should be noted that the success of the call to ``r.json()`` does **not**\n indicate the success of the response. Some servers may return a JSON object in a\n" } ]
{ "header": "If completing this task requires creating new files, classes, fields, or error messages, you may consider using the following suggested entity names:", "data": [] }
diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index b4649f00..73d0b293 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -153,9 +153,9 @@ There's also a builtin JSON decoder, in case you're dealing with JSON data:: In case the JSON decoding fails, ``r.json()`` raises an exception. For example, if the response gets a 204 (No Content), or if the response contains invalid JSON, -attempting ``r.json()`` raises ``simplejson.JSONDecodeError`` if simplejson is -installed or raises ``ValueError: No JSON object could be decoded`` on Python 2 or -``json.JSONDecodeError`` on Python 3. +attempting ``r.json()`` raises ``requests.exceptions.JSONDecodeError``. This wrapper exception +provides interoperability for multiple exceptions that may be thrown by different +python versions and json serialization libraries. It should be noted that the success of the call to ``r.json()`` does **not** indicate the success of the response. Some servers may return a JSON object in a
pytest-dev/pytest
pytest-dev__pytest-2794
https://github.com/pytest-dev/pytest/pull/2794
diff --git a/AUTHORS b/AUTHORS index cf31e038961..2fd2ab15e5d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -166,6 +166,7 @@ Tarcisio Fischer Tareq Alayan Ted Xiao Thomas Grainger +Thomas Hisch Tom Viner Trevor Bekolay Tyler Goodlet diff --git a/_pytest/config.py b/_pytest/config.py index 690f9858774..0d77cfbbf04 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -105,7 +105,7 @@ def directory_arg(path, optname): "mark main terminal runner python fixtures debugging unittest capture skipping " "tmpdir monkeypatch recwarn pastebin helpconfig nose assertion " "junitxml resultlog doctest cacheprovider freeze_support " - "setuponly setupplan warnings").split() + "setuponly setupplan warnings logging").split() builtin_plugins = set(default_plugins) diff --git a/_pytest/logging.py b/_pytest/logging.py new file mode 100644 index 00000000000..ed4db25ad44 --- /dev/null +++ b/_pytest/logging.py @@ -0,0 +1,337 @@ +from __future__ import absolute_import, division, print_function + +import logging +from contextlib import closing, contextmanager +import sys +import six + +import pytest +import py + + +DEFAULT_LOG_FORMAT = '%(filename)-25s %(lineno)4d %(levelname)-8s %(message)s' +DEFAULT_LOG_DATE_FORMAT = '%H:%M:%S' + + +def get_option_ini(config, *names): + for name in names: + ret = config.getoption(name) # 'default' arg won't work as expected + if ret is None: + ret = config.getini(name) + if ret: + return ret + + +def pytest_addoption(parser): + """Add options to control log capturing.""" + group = parser.getgroup('logging') + + def add_option_ini(option, dest, default=None, type=None, **kwargs): + parser.addini(dest, default=default, type=type, + help='default value for ' + option) + group.addoption(option, dest=dest, **kwargs) + + add_option_ini( + '--no-print-logs', + dest='log_print', action='store_const', const=False, default=True, + type='bool', + help='disable printing caught logs on failed tests.') + add_option_ini( + '--log-level', + dest='log_level', default=None, + help='logging level used by the logging module') + add_option_ini( + '--log-format', + dest='log_format', default=DEFAULT_LOG_FORMAT, + help='log format as used by the logging module.') + add_option_ini( + '--log-date-format', + dest='log_date_format', default=DEFAULT_LOG_DATE_FORMAT, + help='log date format as used by the logging module.') + add_option_ini( + '--log-cli-level', + dest='log_cli_level', default=None, + help='cli logging level.') + add_option_ini( + '--log-cli-format', + dest='log_cli_format', default=None, + help='log format as used by the logging module.') + add_option_ini( + '--log-cli-date-format', + dest='log_cli_date_format', default=None, + help='log date format as used by the logging module.') + add_option_ini( + '--log-file', + dest='log_file', default=None, + help='path to a file when logging will be written to.') + add_option_ini( + '--log-file-level', + dest='log_file_level', default=None, + help='log file logging level.') + add_option_ini( + '--log-file-format', + dest='log_file_format', default=DEFAULT_LOG_FORMAT, + help='log format as used by the logging module.') + add_option_ini( + '--log-file-date-format', + dest='log_file_date_format', default=DEFAULT_LOG_DATE_FORMAT, + help='log date format as used by the logging module.') + + +@contextmanager +def logging_using_handler(handler, logger=None): + """Context manager that safely registers a given handler.""" + logger = logger or logging.getLogger(logger) + + if handler in logger.handlers: # reentrancy + # Adding the same handler twice would confuse logging system. + # Just don't do that. + yield + else: + logger.addHandler(handler) + try: + yield + finally: + logger.removeHandler(handler) + + +@contextmanager +def catching_logs(handler, formatter=None, + level=logging.NOTSET, logger=None): + """Context manager that prepares the whole logging machinery properly.""" + logger = logger or logging.getLogger(logger) + + if formatter is not None: + handler.setFormatter(formatter) + handler.setLevel(level) + + with logging_using_handler(handler, logger): + orig_level = logger.level + logger.setLevel(min(orig_level, level)) + try: + yield handler + finally: + logger.setLevel(orig_level) + + +class LogCaptureHandler(logging.StreamHandler): + """A logging handler that stores log records and the log text.""" + + def __init__(self): + """Creates a new log handler.""" + logging.StreamHandler.__init__(self, py.io.TextIO()) + self.records = [] + + def emit(self, record): + """Keep the log records in a list in addition to the log text.""" + self.records.append(record) + logging.StreamHandler.emit(self, record) + + +class LogCaptureFixture(object): + """Provides access and control of log capturing.""" + + def __init__(self, item): + """Creates a new funcarg.""" + self._item = item + + @property + def handler(self): + return self._item.catch_log_handler + + @property + def text(self): + """Returns the log text.""" + return self.handler.stream.getvalue() + + @property + def records(self): + """Returns the list of log records.""" + return self.handler.records + + @property + def record_tuples(self): + """Returns a list of a striped down version of log records intended + for use in assertion comparison. + + The format of the tuple is: + + (logger_name, log_level, message) + """ + return [(r.name, r.levelno, r.getMessage()) for r in self.records] + + def clear(self): + """Reset the list of log records.""" + self.handler.records = [] + + def set_level(self, level, logger=None): + """Sets the level for capturing of logs. + + By default, the level is set on the handler used to capture + logs. Specify a logger name to instead set the level of any + logger. + """ + if logger is None: + logger = self.handler + else: + logger = logging.getLogger(logger) + logger.setLevel(level) + + @contextmanager + def at_level(self, level, logger=None): + """Context manager that sets the level for capturing of logs. + + By default, the level is set on the handler used to capture + logs. Specify a logger name to instead set the level of any + logger. + """ + if logger is None: + logger = self.handler + else: + logger = logging.getLogger(logger) + + orig_level = logger.level + logger.setLevel(level) + try: + yield + finally: + logger.setLevel(orig_level) + + +@pytest.fixture +def caplog(request): + """Access and control log capturing. + + Captured logs are available through the following methods:: + + * caplog.text() -> string containing formatted log output + * caplog.records() -> list of logging.LogRecord instances + * caplog.record_tuples() -> list of (logger_name, level, message) tuples + """ + return LogCaptureFixture(request.node) + + +def get_actual_log_level(config, *setting_names): + """Return the actual logging level.""" + + for setting_name in setting_names: + log_level = config.getoption(setting_name) + if log_level is None: + log_level = config.getini(setting_name) + if log_level: + break + else: + return + + if isinstance(log_level, six.string_types): + log_level = log_level.upper() + try: + return int(getattr(logging, log_level, log_level)) + except ValueError: + # Python logging does not recognise this as a logging level + raise pytest.UsageError( + "'{0}' is not recognized as a logging level name for " + "'{1}'. Please consider passing the " + "logging level num instead.".format( + log_level, + setting_name)) + + +def pytest_configure(config): + config.pluginmanager.register(LoggingPlugin(config), + 'logging-plugin') + + +class LoggingPlugin(object): + """Attaches to the logging module and captures log messages for each test. + """ + + def __init__(self, config): + """Creates a new plugin to capture log messages. + + The formatter can be safely shared across all handlers so + create a single one for the entire test session here. + """ + self.log_cli_level = get_actual_log_level( + config, 'log_cli_level', 'log_level') or logging.WARNING + + self.print_logs = get_option_ini(config, 'log_print') + self.formatter = logging.Formatter( + get_option_ini(config, 'log_format'), + get_option_ini(config, 'log_date_format')) + + log_cli_handler = logging.StreamHandler(sys.stderr) + log_cli_format = get_option_ini( + config, 'log_cli_format', 'log_format') + log_cli_date_format = get_option_ini( + config, 'log_cli_date_format', 'log_date_format') + log_cli_formatter = logging.Formatter( + log_cli_format, + datefmt=log_cli_date_format) + self.log_cli_handler = log_cli_handler # needed for a single unittest + self.live_logs = catching_logs(log_cli_handler, + formatter=log_cli_formatter, + level=self.log_cli_level) + + log_file = get_option_ini(config, 'log_file') + if log_file: + self.log_file_level = get_actual_log_level( + config, 'log_file_level') or logging.WARNING + + log_file_format = get_option_ini( + config, 'log_file_format', 'log_format') + log_file_date_format = get_option_ini( + config, 'log_file_date_format', 'log_date_format') + self.log_file_handler = logging.FileHandler( + log_file, + # Each pytest runtests session will write to a clean logfile + mode='w') + log_file_formatter = logging.Formatter( + log_file_format, + datefmt=log_file_date_format) + self.log_file_handler.setFormatter(log_file_formatter) + else: + self.log_file_handler = None + + @contextmanager + def _runtest_for(self, item, when): + """Implements the internals of pytest_runtest_xxx() hook.""" + with catching_logs(LogCaptureHandler(), + formatter=self.formatter) as log_handler: + item.catch_log_handler = log_handler + try: + yield # run test + finally: + del item.catch_log_handler + + if self.print_logs: + # Add a captured log section to the report. + log = log_handler.stream.getvalue().strip() + item.add_report_section(when, 'log', log) + + @pytest.hookimpl(hookwrapper=True) + def pytest_runtest_setup(self, item): + with self._runtest_for(item, 'setup'): + yield + + @pytest.hookimpl(hookwrapper=True) + def pytest_runtest_call(self, item): + with self._runtest_for(item, 'call'): + yield + + @pytest.hookimpl(hookwrapper=True) + def pytest_runtest_teardown(self, item): + with self._runtest_for(item, 'teardown'): + yield + + @pytest.hookimpl(hookwrapper=True) + def pytest_runtestloop(self, session): + """Runs all collected test items.""" + with self.live_logs: + if self.log_file_handler is not None: + with closing(self.log_file_handler): + with catching_logs(self.log_file_handler, + level=self.log_file_level): + yield # run all the tests + else: + yield # run all the tests diff --git a/changelog/2794.feature b/changelog/2794.feature new file mode 100644 index 00000000000..9cff1c4bb6c --- /dev/null +++ b/changelog/2794.feature @@ -0,0 +1,3 @@ +Pytest now captures and displays output from the standard `logging` module. The user can control the logging level to be captured by specifying options in ``pytest.ini``, the command line and also during individual tests using markers. Also, a ``caplog`` fixture is available that enables users to test the captured log during specific tests (similar to ``capsys`` for example). For more information, please see the `docs <https://docs.pytest.org/en/latest/logging.html>`_. + +This feature was introduced by merging the popular `pytest-catchlog <https://pypi.org/project/pytest-catchlog/>`_ plugin, thanks to `Thomas Hisch <https://github.com/thisch>`_. Be advised that during the merging the backward compatibility interface with the defunct ``pytest-capturelog`` has been dropped. \ No newline at end of file diff --git a/doc/en/contents.rst b/doc/en/contents.rst index 028414eb658..12dbce2ee17 100644 --- a/doc/en/contents.rst +++ b/doc/en/contents.rst @@ -30,6 +30,7 @@ Full pytest documentation xunit_setup plugins writing_plugins + logging goodpractices pythonpath diff --git a/doc/en/logging.rst b/doc/en/logging.rst new file mode 100644 index 00000000000..e3bf5603887 --- /dev/null +++ b/doc/en/logging.rst @@ -0,0 +1,192 @@ +.. _logging: + +Logging +------- + +.. versionadded 3.3.0 + +.. note:: + + This feature is a drop-in replacement for the `pytest-catchlog + <https://pypi.org/project/pytest-catchlog/>`_ plugin and they will conflict + with each other. The backward compatibility API with ``pytest-capturelog`` + has been dropped when this feature was introduced, so if for that reason you + still need ``pytest-catchlog`` you can disable the internal feature by + adding to your ``pytest.ini``: + + .. code-block:: ini + + [pytest] + addopts=-p no:logging + +Log messages are captured by default and for each failed test will be shown in +the same manner as captured stdout and stderr. + +Running without options:: + + pytest + +Shows failed tests like so:: + + ----------------------- Captured stdlog call ---------------------- + test_reporting.py 26 INFO text going to logger + ----------------------- Captured stdout call ---------------------- + text going to stdout + ----------------------- Captured stderr call ---------------------- + text going to stderr + ==================== 2 failed in 0.02 seconds ===================== + +By default each captured log message shows the module, line number, log level +and message. Showing the exact module and line number is useful for testing and +debugging. If desired the log format and date format can be specified to +anything that the logging module supports. + +Running pytest specifying formatting options:: + + pytest --log-format="%(asctime)s %(levelname)s %(message)s" \ + --log-date-format="%Y-%m-%d %H:%M:%S" + +Shows failed tests like so:: + + ----------------------- Captured stdlog call ---------------------- + 2010-04-10 14:48:44 INFO text going to logger + ----------------------- Captured stdout call ---------------------- + text going to stdout + ----------------------- Captured stderr call ---------------------- + text going to stderr + ==================== 2 failed in 0.02 seconds ===================== + +These options can also be customized through a configuration file: + +.. code-block:: ini + + [pytest] + log_format = %(asctime)s %(levelname)s %(message)s + log_date_format = %Y-%m-%d %H:%M:%S + +Further it is possible to disable reporting logs on failed tests completely +with:: + + pytest --no-print-logs + +Or in you ``pytest.ini``: + +.. code-block:: ini + + [pytest] + log_print = False + + +Shows failed tests in the normal manner as no logs were captured:: + + ----------------------- Captured stdout call ---------------------- + text going to stdout + ----------------------- Captured stderr call ---------------------- + text going to stderr + ==================== 2 failed in 0.02 seconds ===================== + +Inside tests it is possible to change the log level for the captured log +messages. This is supported by the ``caplog`` fixture:: + + def test_foo(caplog): + caplog.set_level(logging.INFO) + pass + +By default the level is set on the handler used to catch the log messages, +however as a convenience it is also possible to set the log level of any +logger:: + + def test_foo(caplog): + caplog.set_level(logging.CRITICAL, logger='root.baz') + pass + +It is also possible to use a context manager to temporarily change the log +level:: + + def test_bar(caplog): + with caplog.at_level(logging.INFO): + pass + +Again, by default the level of the handler is affected but the level of any +logger can be changed instead with:: + + def test_bar(caplog): + with caplog.at_level(logging.CRITICAL, logger='root.baz'): + pass + +Lastly all the logs sent to the logger during the test run are made available on +the fixture in the form of both the LogRecord instances and the final log text. +This is useful for when you want to assert on the contents of a message:: + + def test_baz(caplog): + func_under_test() + for record in caplog.records: + assert record.levelname != 'CRITICAL' + assert 'wally' not in caplog.text + +For all the available attributes of the log records see the +``logging.LogRecord`` class. + +You can also resort to ``record_tuples`` if all you want to do is to ensure, +that certain messages have been logged under a given logger name with a given +severity and message:: + + def test_foo(caplog): + logging.getLogger().info('boo %s', 'arg') + + assert caplog.record_tuples == [ + ('root', logging.INFO, 'boo arg'), + ] + +You can call ``caplog.clear()`` to reset the captured log records in a test:: + + def test_something_with_clearing_records(caplog): + some_method_that_creates_log_records() + caplog.clear() + your_test_method() + assert ['Foo'] == [rec.message for rec in caplog.records] + +Live Logs +^^^^^^^^^ + +By default, pytest will output any logging records with a level higher or +equal to WARNING. In order to actually see these logs in the console you have to +disable pytest output capture by passing ``-s``. + +You can specify the logging level for which log records with equal or higher +level are printed to the console by passing ``--log-cli-level``. This setting +accepts the logging level names as seen in python's documentation or an integer +as the logging level num. + +Additionally, you can also specify ``--log-cli-format`` and +``--log-cli-date-format`` which mirror and default to ``--log-format`` and +``--log-date-format`` if not provided, but are applied only to the console +logging handler. + +All of the CLI log options can also be set in the configuration INI file. The +option names are: + +* ``log_cli_level`` +* ``log_cli_format`` +* ``log_cli_date_format`` + +If you need to record the whole test suite logging calls to a file, you can pass +``--log-file=/path/to/log/file``. This log file is opened in write mode which +means that it will be overwritten at each run tests session. + +You can also specify the logging level for the log file by passing +``--log-file-level``. This setting accepts the logging level names as seen in +python's documentation(ie, uppercased level names) or an integer as the logging +level num. + +Additionally, you can also specify ``--log-file-format`` and +``--log-file-date-format`` which are equal to ``--log-format`` and +``--log-date-format`` but are applied to the log file logging handler. + +All of the log file options can also be set in the configuration INI file. The +option names are: + +* ``log_file`` +* ``log_file_level`` +* ``log_file_format`` +* ``log_file_date_format`` diff --git a/doc/en/plugins.rst b/doc/en/plugins.rst index ec031e9e033..bba7d3ecd74 100644 --- a/doc/en/plugins.rst +++ b/doc/en/plugins.rst @@ -27,9 +27,6 @@ Here is a little annotated list for some popular plugins: for `twisted <http://twistedmatrix.com>`_ apps, starting a reactor and processing deferreds from test functions. -* `pytest-catchlog <http://pypi.python.org/pypi/pytest-catchlog>`_: - to capture and assert about messages from the logging module - * `pytest-cov <http://pypi.python.org/pypi/pytest-cov>`_: coverage reporting, compatible with distributed testing diff --git a/doc/en/usage.rst b/doc/en/usage.rst index a8c6d40a027..1cb64ec8745 100644 --- a/doc/en/usage.rst +++ b/doc/en/usage.rst @@ -189,7 +189,6 @@ in your code and pytest automatically disables its output capture for that test: for test output occurring after you exit the interactive PDB_ tracing session and continue with the regular test run. - .. _durations: Profiling test execution duration diff --git a/setup.py b/setup.py index 4d74e6bca3a..27d066fbacd 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ def has_environment_marker_support(): def main(): - install_requires = ['py>=1.4.33', 'six>=1.10.0', 'setuptools'] + install_requires = ['py>=1.4.34', 'six>=1.10.0', 'setuptools'] # if _PYTEST_SETUP_SKIP_PLUGGY_DEP is set, skip installing pluggy; # used by tox.ini to test with pluggy master if '_PYTEST_SETUP_SKIP_PLUGGY_DEP' not in os.environ:
diff --git a/testing/logging/test_fixture.py b/testing/logging/test_fixture.py new file mode 100644 index 00000000000..b5bee4233a5 --- /dev/null +++ b/testing/logging/test_fixture.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +import logging + + +logger = logging.getLogger(__name__) +sublogger = logging.getLogger(__name__+'.baz') + + +def test_fixture_help(testdir): + result = testdir.runpytest('--fixtures') + result.stdout.fnmatch_lines(['*caplog*']) + + +def test_change_level(caplog): + caplog.set_level(logging.INFO) + logger.debug('handler DEBUG level') + logger.info('handler INFO level') + + caplog.set_level(logging.CRITICAL, logger=sublogger.name) + sublogger.warning('logger WARNING level') + sublogger.critical('logger CRITICAL level') + + assert 'DEBUG' not in caplog.text + assert 'INFO' in caplog.text + assert 'WARNING' not in caplog.text + assert 'CRITICAL' in caplog.text + + +def test_with_statement(caplog): + with caplog.at_level(logging.INFO): + logger.debug('handler DEBUG level') + logger.info('handler INFO level') + + with caplog.at_level(logging.CRITICAL, logger=sublogger.name): + sublogger.warning('logger WARNING level') + sublogger.critical('logger CRITICAL level') + + assert 'DEBUG' not in caplog.text + assert 'INFO' in caplog.text + assert 'WARNING' not in caplog.text + assert 'CRITICAL' in caplog.text + + +def test_log_access(caplog): + logger.info('boo %s', 'arg') + assert caplog.records[0].levelname == 'INFO' + assert caplog.records[0].msg == 'boo %s' + assert 'boo arg' in caplog.text + + +def test_record_tuples(caplog): + logger.info('boo %s', 'arg') + + assert caplog.record_tuples == [ + (__name__, logging.INFO, 'boo arg'), + ] + + +def test_unicode(caplog): + logger.info(u'bū') + assert caplog.records[0].levelname == 'INFO' + assert caplog.records[0].msg == u'bū' + assert u'bū' in caplog.text + + +def test_clear(caplog): + logger.info(u'bū') + assert len(caplog.records) + caplog.clear() + assert not len(caplog.records) diff --git a/testing/logging/test_reporting.py b/testing/logging/test_reporting.py new file mode 100644 index 00000000000..c02ee217227 --- /dev/null +++ b/testing/logging/test_reporting.py @@ -0,0 +1,398 @@ +# -*- coding: utf-8 -*- +import os +import pytest + + +def test_nothing_logged(testdir): + testdir.makepyfile(''' + import sys + + def test_foo(): + sys.stdout.write('text going to stdout') + sys.stderr.write('text going to stderr') + assert False + ''') + result = testdir.runpytest() + assert result.ret == 1 + result.stdout.fnmatch_lines(['*- Captured stdout call -*', + 'text going to stdout']) + result.stdout.fnmatch_lines(['*- Captured stderr call -*', + 'text going to stderr']) + with pytest.raises(pytest.fail.Exception): + result.stdout.fnmatch_lines(['*- Captured *log call -*']) + + +def test_messages_logged(testdir): + testdir.makepyfile(''' + import sys + import logging + + logger = logging.getLogger(__name__) + + def test_foo(): + sys.stdout.write('text going to stdout') + sys.stderr.write('text going to stderr') + logger.info('text going to logger') + assert False + ''') + result = testdir.runpytest() + assert result.ret == 1 + result.stdout.fnmatch_lines(['*- Captured *log call -*', + '*text going to logger*']) + result.stdout.fnmatch_lines(['*- Captured stdout call -*', + 'text going to stdout']) + result.stdout.fnmatch_lines(['*- Captured stderr call -*', + 'text going to stderr']) + + +def test_setup_logging(testdir): + testdir.makepyfile(''' + import logging + + logger = logging.getLogger(__name__) + + def setup_function(function): + logger.info('text going to logger from setup') + + def test_foo(): + logger.info('text going to logger from call') + assert False + ''') + result = testdir.runpytest() + assert result.ret == 1 + result.stdout.fnmatch_lines(['*- Captured *log setup -*', + '*text going to logger from setup*', + '*- Captured *log call -*', + '*text going to logger from call*']) + + +def test_teardown_logging(testdir): + testdir.makepyfile(''' + import logging + + logger = logging.getLogger(__name__) + + def test_foo(): + logger.info('text going to logger from call') + + def teardown_function(function): + logger.info('text going to logger from teardown') + assert False + ''') + result = testdir.runpytest() + assert result.ret == 1 + result.stdout.fnmatch_lines(['*- Captured *log call -*', + '*text going to logger from call*', + '*- Captured *log teardown -*', + '*text going to logger from teardown*']) + + +def test_disable_log_capturing(testdir): + testdir.makepyfile(''' + import sys + import logging + + logger = logging.getLogger(__name__) + + def test_foo(): + sys.stdout.write('text going to stdout') + logger.warning('catch me if you can!') + sys.stderr.write('text going to stderr') + assert False + ''') + result = testdir.runpytest('--no-print-logs') + print(result.stdout) + assert result.ret == 1 + result.stdout.fnmatch_lines(['*- Captured stdout call -*', + 'text going to stdout']) + result.stdout.fnmatch_lines(['*- Captured stderr call -*', + 'text going to stderr']) + with pytest.raises(pytest.fail.Exception): + result.stdout.fnmatch_lines(['*- Captured *log call -*']) + + +def test_disable_log_capturing_ini(testdir): + testdir.makeini( + ''' + [pytest] + log_print=False + ''' + ) + testdir.makepyfile(''' + import sys + import logging + + logger = logging.getLogger(__name__) + + def test_foo(): + sys.stdout.write('text going to stdout') + logger.warning('catch me if you can!') + sys.stderr.write('text going to stderr') + assert False + ''') + result = testdir.runpytest() + print(result.stdout) + assert result.ret == 1 + result.stdout.fnmatch_lines(['*- Captured stdout call -*', + 'text going to stdout']) + result.stdout.fnmatch_lines(['*- Captured stderr call -*', + 'text going to stderr']) + with pytest.raises(pytest.fail.Exception): + result.stdout.fnmatch_lines(['*- Captured *log call -*']) + + +def test_log_cli_default_level(testdir): + # Default log file level + testdir.makepyfile(''' + import pytest + import logging + def test_log_cli(request): + plugin = request.config.pluginmanager.getplugin('logging-plugin') + assert plugin.log_cli_handler.level == logging.WARNING + logging.getLogger('catchlog').info("This log message won't be shown") + logging.getLogger('catchlog').warning("This log message will be shown") + print('PASSED') + ''') + + result = testdir.runpytest('-s') + + # fnmatch_lines does an assertion internally + result.stdout.fnmatch_lines([ + 'test_log_cli_default_level.py PASSED', + ]) + result.stderr.fnmatch_lines([ + "* This log message will be shown" + ]) + for line in result.errlines: + try: + assert "This log message won't be shown" in line + pytest.fail("A log message was shown and it shouldn't have been") + except AssertionError: + continue + + # make sure that that we get a '0' exit code for the testsuite + assert result.ret == 0 + + +def test_log_cli_level(testdir): + # Default log file level + testdir.makepyfile(''' + import pytest + import logging + def test_log_cli(request): + plugin = request.config.pluginmanager.getplugin('logging-plugin') + assert plugin.log_cli_handler.level == logging.INFO + logging.getLogger('catchlog').debug("This log message won't be shown") + logging.getLogger('catchlog').info("This log message will be shown") + print('PASSED') + ''') + + result = testdir.runpytest('-s', '--log-cli-level=INFO') + + # fnmatch_lines does an assertion internally + result.stdout.fnmatch_lines([ + 'test_log_cli_level.py PASSED', + ]) + result.stderr.fnmatch_lines([ + "* This log message will be shown" + ]) + for line in result.errlines: + try: + assert "This log message won't be shown" in line + pytest.fail("A log message was shown and it shouldn't have been") + except AssertionError: + continue + + # make sure that that we get a '0' exit code for the testsuite + assert result.ret == 0 + + result = testdir.runpytest('-s', '--log-level=INFO') + + # fnmatch_lines does an assertion internally + result.stdout.fnmatch_lines([ + 'test_log_cli_level.py PASSED', + ]) + result.stderr.fnmatch_lines([ + "* This log message will be shown" + ]) + for line in result.errlines: + try: + assert "This log message won't be shown" in line + pytest.fail("A log message was shown and it shouldn't have been") + except AssertionError: + continue + + # make sure that that we get a '0' exit code for the testsuite + assert result.ret == 0 + + +def test_log_cli_ini_level(testdir): + testdir.makeini( + """ + [pytest] + log_cli_level = INFO + """) + testdir.makepyfile(''' + import pytest + import logging + def test_log_cli(request): + plugin = request.config.pluginmanager.getplugin('logging-plugin') + assert plugin.log_cli_handler.level == logging.INFO + logging.getLogger('catchlog').debug("This log message won't be shown") + logging.getLogger('catchlog').info("This log message will be shown") + print('PASSED') + ''') + + result = testdir.runpytest('-s') + + # fnmatch_lines does an assertion internally + result.stdout.fnmatch_lines([ + 'test_log_cli_ini_level.py PASSED', + ]) + result.stderr.fnmatch_lines([ + "* This log message will be shown" + ]) + for line in result.errlines: + try: + assert "This log message won't be shown" in line + pytest.fail("A log message was shown and it shouldn't have been") + except AssertionError: + continue + + # make sure that that we get a '0' exit code for the testsuite + assert result.ret == 0 + + +def test_log_file_cli(testdir): + # Default log file level + testdir.makepyfile(''' + import pytest + import logging + def test_log_file(request): + plugin = request.config.pluginmanager.getplugin('logging-plugin') + assert plugin.log_file_handler.level == logging.WARNING + logging.getLogger('catchlog').info("This log message won't be shown") + logging.getLogger('catchlog').warning("This log message will be shown") + print('PASSED') + ''') + + log_file = testdir.tmpdir.join('pytest.log').strpath + + result = testdir.runpytest('-s', '--log-file={0}'.format(log_file)) + + # fnmatch_lines does an assertion internally + result.stdout.fnmatch_lines([ + 'test_log_file_cli.py PASSED', + ]) + + # make sure that that we get a '0' exit code for the testsuite + assert result.ret == 0 + assert os.path.isfile(log_file) + with open(log_file) as rfh: + contents = rfh.read() + assert "This log message will be shown" in contents + assert "This log message won't be shown" not in contents + + +def test_log_file_cli_level(testdir): + # Default log file level + testdir.makepyfile(''' + import pytest + import logging + def test_log_file(request): + plugin = request.config.pluginmanager.getplugin('logging-plugin') + assert plugin.log_file_handler.level == logging.INFO + logging.getLogger('catchlog').debug("This log message won't be shown") + logging.getLogger('catchlog').info("This log message will be shown") + print('PASSED') + ''') + + log_file = testdir.tmpdir.join('pytest.log').strpath + + result = testdir.runpytest('-s', + '--log-file={0}'.format(log_file), + '--log-file-level=INFO') + + # fnmatch_lines does an assertion internally + result.stdout.fnmatch_lines([ + 'test_log_file_cli_level.py PASSED', + ]) + + # make sure that that we get a '0' exit code for the testsuite + assert result.ret == 0 + assert os.path.isfile(log_file) + with open(log_file) as rfh: + contents = rfh.read() + assert "This log message will be shown" in contents + assert "This log message won't be shown" not in contents + + +def test_log_file_ini(testdir): + log_file = testdir.tmpdir.join('pytest.log').strpath + + testdir.makeini( + """ + [pytest] + log_file={0} + """.format(log_file)) + testdir.makepyfile(''' + import pytest + import logging + def test_log_file(request): + plugin = request.config.pluginmanager.getplugin('logging-plugin') + assert plugin.log_file_handler.level == logging.WARNING + logging.getLogger('catchlog').info("This log message won't be shown") + logging.getLogger('catchlog').warning("This log message will be shown") + print('PASSED') + ''') + + result = testdir.runpytest('-s') + + # fnmatch_lines does an assertion internally + result.stdout.fnmatch_lines([ + 'test_log_file_ini.py PASSED', + ]) + + # make sure that that we get a '0' exit code for the testsuite + assert result.ret == 0 + assert os.path.isfile(log_file) + with open(log_file) as rfh: + contents = rfh.read() + assert "This log message will be shown" in contents + assert "This log message won't be shown" not in contents + + +def test_log_file_ini_level(testdir): + log_file = testdir.tmpdir.join('pytest.log').strpath + + testdir.makeini( + """ + [pytest] + log_file={0} + log_file_level = INFO + """.format(log_file)) + testdir.makepyfile(''' + import pytest + import logging + def test_log_file(request): + plugin = request.config.pluginmanager.getplugin('logging-plugin') + assert plugin.log_file_handler.level == logging.INFO + logging.getLogger('catchlog').debug("This log message won't be shown") + logging.getLogger('catchlog').info("This log message will be shown") + print('PASSED') + ''') + + result = testdir.runpytest('-s') + + # fnmatch_lines does an assertion internally + result.stdout.fnmatch_lines([ + 'test_log_file_ini_level.py PASSED', + ]) + + # make sure that that we get a '0' exit code for the testsuite + assert result.ret == 0 + assert os.path.isfile(log_file) + with open(log_file) as rfh: + contents = rfh.read() + assert "This log message will be shown" in contents + assert "This log message won't be shown" not in contents diff --git a/testing/test_capture.py b/testing/test_capture.py index eb10f3c0725..336ca9ef01e 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -342,26 +342,6 @@ def teardown_module(function): # verify proper termination assert "closed" not in s - def test_logging_initialized_in_test(self, testdir): - p = testdir.makepyfile(""" - import sys - def test_something(): - # pytest does not import logging - assert 'logging' not in sys.modules - import logging - logging.basicConfig() - logging.warn("hello432") - assert 0 - """) - result = testdir.runpytest_subprocess( - p, "--traceconfig", - "-p", "no:capturelog", "-p", "no:hypothesis", "-p", "no:hypothesispytest") - assert result.ret != 0 - result.stdout.fnmatch_lines([ - "*hello432*", - ]) - assert 'operation on closed file' not in result.stderr.str() - def test_conftestlogging_is_shown(self, testdir): testdir.makeconftest(""" import logging
[ { "path": "doc/en/contents.rst", "old_path": "a/doc/en/contents.rst", "new_path": "b/doc/en/contents.rst", "metadata": "diff --git a/doc/en/contents.rst b/doc/en/contents.rst\nindex 028414eb658..12dbce2ee17 100644\n--- a/doc/en/contents.rst\n+++ b/doc/en/contents.rst\n@@ -30,6 +30,7 @@ Full pytest documentation\n xunit_setup\n plugins\n writing_plugins\n+ logging\n \n goodpractices\n pythonpath\n", "update": null }, { "path": "doc/en/logging.rst", "old_path": "/dev/null", "new_path": "b/doc/en/logging.rst", "metadata": "diff --git a/doc/en/logging.rst b/doc/en/logging.rst\nnew file mode 100644\nindex 00000000000..e3bf5603887\n--- /dev/null\n+++ b/doc/en/logging.rst\n@@ -0,0 +1,192 @@\n+.. _logging:\n+\n+Logging\n+-------\n+\n+.. versionadded 3.3.0\n+\n+.. note::\n+\n+ This feature is a drop-in replacement for the `pytest-catchlog\n+ <https://pypi.org/project/pytest-catchlog/>`_ plugin and they will conflict\n+ with each other. The backward compatibility API with ``pytest-capturelog``\n+ has been dropped when this feature was introduced, so if for that reason you\n+ still need ``pytest-catchlog`` you can disable the internal feature by\n+ adding to your ``pytest.ini``:\n+\n+ .. code-block:: ini\n+\n+ [pytest]\n+ addopts=-p no:logging\n+\n+Log messages are captured by default and for each failed test will be shown in\n+the same manner as captured stdout and stderr.\n+\n+Running without options::\n+\n+ pytest\n+\n+Shows failed tests like so::\n+\n+ ----------------------- Captured stdlog call ----------------------\n+ test_reporting.py 26 INFO text going to logger\n+ ----------------------- Captured stdout call ----------------------\n+ text going to stdout\n+ ----------------------- Captured stderr call ----------------------\n+ text going to stderr\n+ ==================== 2 failed in 0.02 seconds =====================\n+\n+By default each captured log message shows the module, line number, log level\n+and message. Showing the exact module and line number is useful for testing and\n+debugging. If desired the log format and date format can be specified to\n+anything that the logging module supports.\n+\n+Running pytest specifying formatting options::\n+\n+ pytest --log-format=\"%(asctime)s %(levelname)s %(message)s\" \\\n+ --log-date-format=\"%Y-%m-%d %H:%M:%S\"\n+\n+Shows failed tests like so::\n+\n+ ----------------------- Captured stdlog call ----------------------\n+ 2010-04-10 14:48:44 INFO text going to logger\n+ ----------------------- Captured stdout call ----------------------\n+ text going to stdout\n+ ----------------------- Captured stderr call ----------------------\n+ text going to stderr\n+ ==================== 2 failed in 0.02 seconds =====================\n+\n+These options can also be customized through a configuration file:\n+\n+.. code-block:: ini\n+\n+ [pytest]\n+ log_format = %(asctime)s %(levelname)s %(message)s\n+ log_date_format = %Y-%m-%d %H:%M:%S\n+\n+Further it is possible to disable reporting logs on failed tests completely\n+with::\n+\n+ pytest --no-print-logs\n+\n+Or in you ``pytest.ini``:\n+\n+.. code-block:: ini\n+\n+ [pytest]\n+ log_print = False\n+\n+\n+Shows failed tests in the normal manner as no logs were captured::\n+\n+ ----------------------- Captured stdout call ----------------------\n+ text going to stdout\n+ ----------------------- Captured stderr call ----------------------\n+ text going to stderr\n+ ==================== 2 failed in 0.02 seconds =====================\n+\n+Inside tests it is possible to change the log level for the captured log\n+messages. This is supported by the ``caplog`` fixture::\n+\n+ def test_foo(caplog):\n+ caplog.set_level(logging.INFO)\n+ pass\n+\n+By default the level is set on the handler used to catch the log messages,\n+however as a convenience it is also possible to set the log level of any\n+logger::\n+\n+ def test_foo(caplog):\n+ caplog.set_level(logging.CRITICAL, logger='root.baz')\n+ pass\n+\n+It is also possible to use a context manager to temporarily change the log\n+level::\n+\n+ def test_bar(caplog):\n+ with caplog.at_level(logging.INFO):\n+ pass\n+\n+Again, by default the level of the handler is affected but the level of any\n+logger can be changed instead with::\n+\n+ def test_bar(caplog):\n+ with caplog.at_level(logging.CRITICAL, logger='root.baz'):\n+ pass\n+\n+Lastly all the logs sent to the logger during the test run are made available on\n+the fixture in the form of both the LogRecord instances and the final log text.\n+This is useful for when you want to assert on the contents of a message::\n+\n+ def test_baz(caplog):\n+ func_under_test()\n+ for record in caplog.records:\n+ assert record.levelname != 'CRITICAL'\n+ assert 'wally' not in caplog.text\n+\n+For all the available attributes of the log records see the\n+``logging.LogRecord`` class.\n+\n+You can also resort to ``record_tuples`` if all you want to do is to ensure,\n+that certain messages have been logged under a given logger name with a given\n+severity and message::\n+\n+ def test_foo(caplog):\n+ logging.getLogger().info('boo %s', 'arg')\n+\n+ assert caplog.record_tuples == [\n+ ('root', logging.INFO, 'boo arg'),\n+ ]\n+\n+You can call ``caplog.clear()`` to reset the captured log records in a test::\n+\n+ def test_something_with_clearing_records(caplog):\n+ some_method_that_creates_log_records()\n+ caplog.clear()\n+ your_test_method()\n+ assert ['Foo'] == [rec.message for rec in caplog.records]\n+\n+Live Logs\n+^^^^^^^^^\n+\n+By default, pytest will output any logging records with a level higher or\n+equal to WARNING. In order to actually see these logs in the console you have to\n+disable pytest output capture by passing ``-s``.\n+\n+You can specify the logging level for which log records with equal or higher\n+level are printed to the console by passing ``--log-cli-level``. This setting\n+accepts the logging level names as seen in python's documentation or an integer\n+as the logging level num.\n+\n+Additionally, you can also specify ``--log-cli-format`` and\n+``--log-cli-date-format`` which mirror and default to ``--log-format`` and\n+``--log-date-format`` if not provided, but are applied only to the console\n+logging handler.\n+\n+All of the CLI log options can also be set in the configuration INI file. The\n+option names are:\n+\n+* ``log_cli_level``\n+* ``log_cli_format``\n+* ``log_cli_date_format``\n+\n+If you need to record the whole test suite logging calls to a file, you can pass\n+``--log-file=/path/to/log/file``. This log file is opened in write mode which\n+means that it will be overwritten at each run tests session.\n+\n+You can also specify the logging level for the log file by passing\n+``--log-file-level``. This setting accepts the logging level names as seen in\n+python's documentation(ie, uppercased level names) or an integer as the logging\n+level num.\n+\n+Additionally, you can also specify ``--log-file-format`` and\n+``--log-file-date-format`` which are equal to ``--log-format`` and\n+``--log-date-format`` but are applied to the log file logging handler.\n+\n+All of the log file options can also be set in the configuration INI file. The\n+option names are:\n+\n+* ``log_file``\n+* ``log_file_level``\n+* ``log_file_format``\n+* ``log_file_date_format``\n", "update": null }, { "path": "doc/en/plugins.rst", "old_path": "a/doc/en/plugins.rst", "new_path": "b/doc/en/plugins.rst", "metadata": "diff --git a/doc/en/plugins.rst b/doc/en/plugins.rst\nindex ec031e9e033..bba7d3ecd74 100644\n--- a/doc/en/plugins.rst\n+++ b/doc/en/plugins.rst\n@@ -27,9 +27,6 @@ Here is a little annotated list for some popular plugins:\n for `twisted <http://twistedmatrix.com>`_ apps, starting a reactor and\n processing deferreds from test functions.\n \n-* `pytest-catchlog <http://pypi.python.org/pypi/pytest-catchlog>`_:\n- to capture and assert about messages from the logging module\n-\n * `pytest-cov <http://pypi.python.org/pypi/pytest-cov>`_:\n coverage reporting, compatible with distributed testing\n \n", "update": null }, { "path": "doc/en/usage.rst", "old_path": "a/doc/en/usage.rst", "new_path": "b/doc/en/usage.rst", "metadata": "diff --git a/doc/en/usage.rst b/doc/en/usage.rst\nindex a8c6d40a027..1cb64ec8745 100644\n--- a/doc/en/usage.rst\n+++ b/doc/en/usage.rst\n@@ -189,7 +189,6 @@ in your code and pytest automatically disables its output capture for that test:\n for test output occurring after you exit the interactive PDB_ tracing session\n and continue with the regular test run.\n \n-\n .. _durations:\n \n Profiling test execution duration\n", "update": null } ]
3.3
1480aed78122016f5b98d3bb2de3cfe272e0e148
[ "testing/test_capture.py::TestCaptureFixture::test_stdfd_functional", "testing/test_capture.py::test_capture_early_option_parsing", "testing/test_capture.py::TestPerTestCapturing::test_capture_and_fixtures", "testing/test_capture.py::test_setup_failure_does_not_kill_capturing", "testing/test_capture.py::TestStdCapture::test_capturing_error_recursive", "testing/test_capture.py::TestLoggingInteraction::test_logging_and_crossscope_fixtures", "testing/test_capture.py::TestCaptureManager::test_capturing_basic_api[sys]", "testing/test_capture.py::TestCaptureFixture::test_capsyscapfd", "testing/test_capture.py::test_capture_binary_output", "testing/test_capture.py::test_capture_badoutput_issue412", "testing/test_capture.py::TestStdCaptureFD::test_just_err_capture", "testing/test_capture.py::test_pickling_and_unpickling_enocded_file", "testing/test_capture.py::TestCaptureManager::test_capturing_basic_api[fd]", "testing/logging/test_reporting.py::test_disable_log_capturing_ini", "testing/test_capture.py::TestStdCapture::test_stdin_restored", "testing/test_capture.py::TestCaptureFixture::test_disabled_capture_fixture[True-capsys]", "testing/test_capture.py::TestStdCaptureFD::test_capturing_readouterr", "testing/test_capture.py::test_capture_not_started_but_reset", "testing/test_capture.py::TestCaptureIO::test_unicode_and_str_mixture", "testing/test_capture.py::TestStdCapture::test_just_err_capture", "testing/test_capture.py::TestLoggingInteraction::test_logging_and_immediate_setupteardown", "testing/test_capture.py::TestFDCapture::test_simple_many", "testing/test_capture.py::test_capturing_unicode[fd]", "testing/test_capture.py::TestCaptureFixture::test_std_functional[opt0]", "testing/test_capture.py::TestPerTestCapturing::test_no_carry_over", "testing/test_capture.py::TestStdCaptureFD::test_capturing_done_simple", "testing/test_capture.py::TestStdCaptureFD::test_stdin_nulled_by_default", "testing/test_capture.py::test_capture_conftest_runtest_setup", "testing/test_capture.py::test_dupfile", "testing/test_capture.py::TestPerTestCapturing::test_teardown_capturing", "testing/test_capture.py::TestCaptureManager::test_getmethod_default_no_fd", "testing/test_capture.py::test_error_during_readouterr", "testing/test_capture.py::TestStdCaptureFD::test_just_out_capture", "testing/test_capture.py::TestStdCapture::test_just_out_capture", "testing/test_capture.py::TestStdCaptureFDinvalidFD::test_stdcapture_fd_invalid_fd", "testing/test_capture.py::test_close_and_capture_again", "testing/test_capture.py::test_dontreadfrominput_has_encoding", "testing/test_capture.py::TestFDCapture::test_simple_fail_second_start", "testing/test_capture.py::TestFDCapture::test_stdin", "testing/test_capture.py::TestStdCaptureFD::test_capturing_reset_simple", "testing/test_capture.py::TestFDCapture::test_simple", "testing/test_capture.py::test_capturing_bytes_in_utf8_encoding[fd]", "testing/test_capture.py::TestLoggingInteraction::test_logging_stream_ownership", "testing/test_capture.py::test_using_capsys_fixture_works_with_sys_stdout_encoding", "testing/test_capture.py::TestStdCaptureFD::test_simple_only_fd", "testing/test_capture.py::TestFDCapture::test_simple_resume_suspend", "testing/test_capture.py::TestLoggingInteraction::test_conftestlogging_and_test_logging", "testing/test_capture.py::TestCaptureIO::test_text", "testing/test_capture.py::TestCaptureFixture::test_std_functional[opt1]", "testing/test_capture.py::TestCaptureFixture::test_fixture_use_by_other_fixtures[capfd]", "testing/test_capture.py::test_fdfuncarg_skips_on_no_osdup", "testing/test_capture.py::TestStdCaptureFD::test_capturing_modify_sysouterr_in_between", "testing/test_capture.py::TestStdCapture::test_capturing_done_simple", "testing/test_capture.py::TestFDCapture::test_writeorg", "testing/test_capture.py::TestCaptureFixture::test_capturing_getfixturevalue", "testing/test_capture.py::TestCaptureFixture::test_keyboardinterrupt_disables_capturing", "testing/test_capture.py::TestCaptureFixture::test_disabled_capture_fixture[True-capfd]", "testing/test_capture.py::TestCaptureFixture::test_disabled_capture_fixture[False-capsys]", "testing/test_capture.py::test_fdcapture_tmpfile_remains_the_same[False]", "testing/test_capture.py::TestStdCaptureFD::test_capturing_error_recursive", "testing/test_capture.py::TestCaptureIO::test_write_bytes_to_buffer", "testing/test_capture.py::TestPerTestCapturing::test_capturing_outerr", "testing/test_capture.py::TestStdCapture::test_reset_twice_error", "testing/test_capture.py::TestLoggingInteraction::test_conftestlogging_is_shown", "testing/test_capture.py::test_capturing_unicode[sys]", "testing/test_capture.py::test_dupfile_on_textio", "testing/test_capture.py::TestStdCaptureFD::test_reset_twice_error", "testing/test_capture.py::TestCaptureFixture::test_partial_setup_failure", "testing/logging/test_reporting.py::test_nothing_logged", "testing/test_capture.py::TestCaptureFixture::test_capture_is_represented_on_failure_issue128[sys]", "testing/test_capture.py::TestCaptureFixture::test_capture_and_logging", "testing/test_capture.py::TestStdCaptureFD::test_stdin_restored", "testing/test_capture.py::test_error_attribute_issue555", "testing/test_capture.py::test_dontreadfrominput", "testing/test_capture.py::TestStdCapture::test_capturing_readouterr_unicode", "testing/test_capture.py::TestFDCapture::test_stderr", "testing/test_capture.py::TestCaptureManager::test_init_capturing", "testing/test_capture.py::test_collect_capturing", "testing/test_capture.py::TestStdCaptureFD::test_capturing_readouterr_unicode", "testing/test_capture.py::TestStdCapture::test_stdin_nulled_by_default", "testing/test_capture.py::TestStdCapture::test_capturing_readouterr", "testing/test_capture.py::TestStdCaptureFD::test_intermingling", "testing/test_capture.py::test_dontreadfrominput_buffer_python3", "testing/test_capture.py::test_dupfile_on_bytesio", "testing/test_capture.py::TestCaptureFixture::test_fixture_use_by_other_fixtures[capsys]", "testing/test_capture.py::test_fdcapture_tmpfile_remains_the_same[True]", "testing/test_capture.py::test_capturing_and_logging_fundamentals[SysCapture]", "testing/test_capture.py::test_bytes_io", "testing/test_capture.py::test_capturing_bytes_in_utf8_encoding[sys]", "testing/test_capture.py::TestCaptureManager::test_capturing_basic_api[no]", "testing/test_capture.py::TestStdCapture::test_capturing_modify_sysouterr_in_between", "testing/test_capture.py::test_capturing_and_logging_fundamentals[FDCapture]", "testing/test_capture.py::TestCaptureFixture::test_capture_is_represented_on_failure_issue128[fd]", "testing/test_capture.py::TestStdCapture::test_capturing_reset_simple", "testing/test_capture.py::TestPerTestCapturing::test_teardown_capturing_final", "testing/test_capture.py::TestCaptureFixture::test_disabled_capture_fixture[False-capfd]" ]
[ "testing/logging/test_reporting.py::test_disable_log_capturing", "testing/logging/test_fixture.py::test_record_tuples", "testing/logging/test_fixture.py::test_clear", "testing/logging/test_fixture.py::test_fixture_help", "testing/logging/test_fixture.py::test_with_statement", "testing/logging/test_reporting.py::test_log_cli_default_level", "testing/logging/test_reporting.py::test_log_file_cli_level", "testing/logging/test_reporting.py::test_log_file_cli", "testing/logging/test_fixture.py::test_unicode", "testing/logging/test_reporting.py::test_log_cli_ini_level", "testing/logging/test_reporting.py::test_setup_logging", "testing/logging/test_reporting.py::test_teardown_logging", "testing/logging/test_reporting.py::test_log_cli_level", "testing/logging/test_fixture.py::test_change_level", "testing/logging/test_fixture.py::test_log_access", "testing/logging/test_reporting.py::test_messages_logged", "testing/logging/test_reporting.py::test_log_file_ini", "testing/logging/test_reporting.py::test_log_file_ini_level" ]
[ { "path": "doc/en/contents.rst", "old_path": "a/doc/en/contents.rst", "new_path": "b/doc/en/contents.rst", "metadata": "diff --git a/doc/en/contents.rst b/doc/en/contents.rst\nindex 6b9eed010..7a6570e0b 100644\n--- a/doc/en/contents.rst\n+++ b/doc/en/contents.rst\n@@ -30,6 +30,7 @@ Full pytest documentation\n xunit_setup\n plugins\n writing_plugins\n+ logging\n \n goodpractices\n pythonpath\n" }, { "path": "doc/en/logging.rst", "old_path": "/dev/null", "new_path": "b/doc/en/logging.rst", "metadata": "diff --git a/doc/en/logging.rst b/doc/en/logging.rst\nnew file mode 100644\nindex 000000000..e3bf56038\n--- /dev/null\n+++ b/doc/en/logging.rst\n@@ -0,0 +1,192 @@\n+.. _logging:\n+\n+Logging\n+-------\n+\n+.. versionadded 3.3.0\n+\n+.. note::\n+\n+ This feature is a drop-in replacement for the `pytest-catchlog\n+ <https://pypi.org/project/pytest-catchlog/>`_ plugin and they will conflict\n+ with each other. The backward compatibility API with ``pytest-capturelog``\n+ has been dropped when this feature was introduced, so if for that reason you\n+ still need ``pytest-catchlog`` you can disable the internal feature by\n+ adding to your ``pytest.ini``:\n+\n+ .. code-block:: ini\n+\n+ [pytest]\n+ addopts=-p no:logging\n+\n+Log messages are captured by default and for each failed test will be shown in\n+the same manner as captured stdout and stderr.\n+\n+Running without options::\n+\n+ pytest\n+\n+Shows failed tests like so::\n+\n+ ----------------------- Captured stdlog call ----------------------\n+ test_reporting.py 26 INFO text going to logger\n+ ----------------------- Captured stdout call ----------------------\n+ text going to stdout\n+ ----------------------- Captured stderr call ----------------------\n+ text going to stderr\n+ ==================== 2 failed in 0.02 seconds =====================\n+\n+By default each captured log message shows the module, line number, log level\n+and message. Showing the exact module and line number is useful for testing and\n+debugging. If desired the log format and date format can be specified to\n+anything that the logging module supports.\n+\n+Running pytest specifying formatting options::\n+\n+ pytest --log-format=\"%(asctime)s %(levelname)s %(message)s\" \\\n+ --log-date-format=\"%Y-%m-%d %H:%M:%S\"\n+\n+Shows failed tests like so::\n+\n+ ----------------------- Captured stdlog call ----------------------\n+ 2010-04-10 14:48:44 INFO text going to logger\n+ ----------------------- Captured stdout call ----------------------\n+ text going to stdout\n+ ----------------------- Captured stderr call ----------------------\n+ text going to stderr\n+ ==================== 2 failed in 0.02 seconds =====================\n+\n+These options can also be customized through a configuration file:\n+\n+.. code-block:: ini\n+\n+ [pytest]\n+ log_format = %(asctime)s %(levelname)s %(message)s\n+ log_date_format = %Y-%m-%d %H:%M:%S\n+\n+Further it is possible to disable reporting logs on failed tests completely\n+with::\n+\n+ pytest --no-print-logs\n+\n+Or in you ``pytest.ini``:\n+\n+.. code-block:: ini\n+\n+ [pytest]\n+ log_print = False\n+\n+\n+Shows failed tests in the normal manner as no logs were captured::\n+\n+ ----------------------- Captured stdout call ----------------------\n+ text going to stdout\n+ ----------------------- Captured stderr call ----------------------\n+ text going to stderr\n+ ==================== 2 failed in 0.02 seconds =====================\n+\n+Inside tests it is possible to change the log level for the captured log\n+messages. This is supported by the ``caplog`` fixture::\n+\n+ def test_foo(caplog):\n+ caplog.set_level(logging.INFO)\n+ pass\n+\n+By default the level is set on the handler used to catch the log messages,\n+however as a convenience it is also possible to set the log level of any\n+logger::\n+\n+ def test_foo(caplog):\n+ caplog.set_level(logging.CRITICAL, logger='root.baz')\n+ pass\n+\n+It is also possible to use a context manager to temporarily change the log\n+level::\n+\n+ def test_bar(caplog):\n+ with caplog.at_level(logging.INFO):\n+ pass\n+\n+Again, by default the level of the handler is affected but the level of any\n+logger can be changed instead with::\n+\n+ def test_bar(caplog):\n+ with caplog.at_level(logging.CRITICAL, logger='root.baz'):\n+ pass\n+\n+Lastly all the logs sent to the logger during the test run are made available on\n+the fixture in the form of both the LogRecord instances and the final log text.\n+This is useful for when you want to assert on the contents of a message::\n+\n+ def test_baz(caplog):\n+ func_under_test()\n+ for record in caplog.records:\n+ assert record.levelname != 'CRITICAL'\n+ assert 'wally' not in caplog.text\n+\n+For all the available attributes of the log records see the\n+``logging.LogRecord`` class.\n+\n+You can also resort to ``record_tuples`` if all you want to do is to ensure,\n+that certain messages have been logged under a given logger name with a given\n+severity and message::\n+\n+ def test_foo(caplog):\n+ logging.getLogger().info('boo %s', 'arg')\n+\n+ assert caplog.record_tuples == [\n+ ('root', logging.INFO, 'boo arg'),\n+ ]\n+\n+You can call ``caplog.clear()`` to reset the captured log records in a test::\n+\n+ def test_something_with_clearing_records(caplog):\n+ some_method_that_creates_log_records()\n+ caplog.clear()\n+ your_test_method()\n+ assert ['Foo'] == [rec.message for rec in caplog.records]\n+\n+Live Logs\n+^^^^^^^^^\n+\n+By default, pytest will output any logging records with a level higher or\n+equal to WARNING. In order to actually see these logs in the console you have to\n+disable pytest output capture by passing ``-s``.\n+\n+You can specify the logging level for which log records with equal or higher\n+level are printed to the console by passing ``--log-cli-level``. This setting\n+accepts the logging level names as seen in python's documentation or an integer\n+as the logging level num.\n+\n+Additionally, you can also specify ``--log-cli-format`` and\n+``--log-cli-date-format`` which mirror and default to ``--log-format`` and\n+``--log-date-format`` if not provided, but are applied only to the console\n+logging handler.\n+\n+All of the CLI log options can also be set in the configuration INI file. The\n+option names are:\n+\n+* ``log_cli_level``\n+* ``log_cli_format``\n+* ``log_cli_date_format``\n+\n+If you need to record the whole test suite logging calls to a file, you can pass\n+``--log-file=/path/to/log/file``. This log file is opened in write mode which\n+means that it will be overwritten at each run tests session.\n+\n+You can also specify the logging level for the log file by passing\n+``--log-file-level``. This setting accepts the logging level names as seen in\n+python's documentation(ie, uppercased level names) or an integer as the logging\n+level num.\n+\n+Additionally, you can also specify ``--log-file-format`` and\n+``--log-file-date-format`` which are equal to ``--log-format`` and\n+``--log-date-format`` but are applied to the log file logging handler.\n+\n+All of the log file options can also be set in the configuration INI file. The\n+option names are:\n+\n+* ``log_file``\n+* ``log_file_level``\n+* ``log_file_format``\n+* ``log_file_date_format``\n" }, { "path": "doc/en/plugins.rst", "old_path": "a/doc/en/plugins.rst", "new_path": "b/doc/en/plugins.rst", "metadata": "diff --git a/doc/en/plugins.rst b/doc/en/plugins.rst\nindex ec031e9e0..bba7d3ecd 100644\n--- a/doc/en/plugins.rst\n+++ b/doc/en/plugins.rst\n@@ -27,9 +27,6 @@ Here is a little annotated list for some popular plugins:\n for `twisted <http://twistedmatrix.com>`_ apps, starting a reactor and\n processing deferreds from test functions.\n \n-* `pytest-catchlog <http://pypi.python.org/pypi/pytest-catchlog>`_:\n- to capture and assert about messages from the logging module\n-\n * `pytest-cov <http://pypi.python.org/pypi/pytest-cov>`_:\n coverage reporting, compatible with distributed testing\n \n" }, { "path": "doc/en/usage.rst", "old_path": "a/doc/en/usage.rst", "new_path": "b/doc/en/usage.rst", "metadata": "diff --git a/doc/en/usage.rst b/doc/en/usage.rst\nindex a8c6d40a0..1cb64ec87 100644\n--- a/doc/en/usage.rst\n+++ b/doc/en/usage.rst\n@@ -189,7 +189,6 @@ in your code and pytest automatically disables its output capture for that test:\n for test output occurring after you exit the interactive PDB_ tracing session\n and continue with the regular test run.\n \n-\n .. _durations:\n \n Profiling test execution duration\n" } ]
{ "header": "If completing this task requires creating new files, classes, fields, or error messages, you may consider using the following suggested entity names:", "data": [ { "type": "file", "name": "_pytest/logging.py" }, { "type": "field", "name": "ret" } ] }
diff --git a/doc/en/contents.rst b/doc/en/contents.rst index 6b9eed010..7a6570e0b 100644 --- a/doc/en/contents.rst +++ b/doc/en/contents.rst @@ -30,6 +30,7 @@ Full pytest documentation xunit_setup plugins writing_plugins + logging goodpractices pythonpath diff --git a/doc/en/logging.rst b/doc/en/logging.rst new file mode 100644 index 000000000..e3bf56038 --- /dev/null +++ b/doc/en/logging.rst @@ -0,0 +1,192 @@ +.. _logging: + +Logging +------- + +.. versionadded 3.3.0 + +.. note:: + + This feature is a drop-in replacement for the `pytest-catchlog + <https://pypi.org/project/pytest-catchlog/>`_ plugin and they will conflict + with each other. The backward compatibility API with ``pytest-capturelog`` + has been dropped when this feature was introduced, so if for that reason you + still need ``pytest-catchlog`` you can disable the internal feature by + adding to your ``pytest.ini``: + + .. code-block:: ini + + [pytest] + addopts=-p no:logging + +Log messages are captured by default and for each failed test will be shown in +the same manner as captured stdout and stderr. + +Running without options:: + + pytest + +Shows failed tests like so:: + + ----------------------- Captured stdlog call ---------------------- + test_reporting.py 26 INFO text going to logger + ----------------------- Captured stdout call ---------------------- + text going to stdout + ----------------------- Captured stderr call ---------------------- + text going to stderr + ==================== 2 failed in 0.02 seconds ===================== + +By default each captured log message shows the module, line number, log level +and message. Showing the exact module and line number is useful for testing and +debugging. If desired the log format and date format can be specified to +anything that the logging module supports. + +Running pytest specifying formatting options:: + + pytest --log-format="%(asctime)s %(levelname)s %(message)s" \ + --log-date-format="%Y-%m-%d %H:%M:%S" + +Shows failed tests like so:: + + ----------------------- Captured stdlog call ---------------------- + 2010-04-10 14:48:44 INFO text going to logger + ----------------------- Captured stdout call ---------------------- + text going to stdout + ----------------------- Captured stderr call ---------------------- + text going to stderr + ==================== 2 failed in 0.02 seconds ===================== + +These options can also be customized through a configuration file: + +.. code-block:: ini + + [pytest] + log_format = %(asctime)s %(levelname)s %(message)s + log_date_format = %Y-%m-%d %H:%M:%S + +Further it is possible to disable reporting logs on failed tests completely +with:: + + pytest --no-print-logs + +Or in you ``pytest.ini``: + +.. code-block:: ini + + [pytest] + log_print = False + + +Shows failed tests in the normal manner as no logs were captured:: + + ----------------------- Captured stdout call ---------------------- + text going to stdout + ----------------------- Captured stderr call ---------------------- + text going to stderr + ==================== 2 failed in 0.02 seconds ===================== + +Inside tests it is possible to change the log level for the captured log +messages. This is supported by the ``caplog`` fixture:: + + def test_foo(caplog): + caplog.set_level(logging.INFO) + pass + +By default the level is set on the handler used to catch the log messages, +however as a convenience it is also possible to set the log level of any +logger:: + + def test_foo(caplog): + caplog.set_level(logging.CRITICAL, logger='root.baz') + pass + +It is also possible to use a context manager to temporarily change the log +level:: + + def test_bar(caplog): + with caplog.at_level(logging.INFO): + pass + +Again, by default the level of the handler is affected but the level of any +logger can be changed instead with:: + + def test_bar(caplog): + with caplog.at_level(logging.CRITICAL, logger='root.baz'): + pass + +Lastly all the logs sent to the logger during the test run are made available on +the fixture in the form of both the LogRecord instances and the final log text. +This is useful for when you want to assert on the contents of a message:: + + def test_baz(caplog): + func_under_test() + for record in caplog.records: + assert record.levelname != 'CRITICAL' + assert 'wally' not in caplog.text + +For all the available attributes of the log records see the +``logging.LogRecord`` class. + +You can also resort to ``record_tuples`` if all you want to do is to ensure, +that certain messages have been logged under a given logger name with a given +severity and message:: + + def test_foo(caplog): + logging.getLogger().info('boo %s', 'arg') + + assert caplog.record_tuples == [ + ('root', logging.INFO, 'boo arg'), + ] + +You can call ``caplog.clear()`` to reset the captured log records in a test:: + + def test_something_with_clearing_records(caplog): + some_method_that_creates_log_records() + caplog.clear() + your_test_method() + assert ['Foo'] == [rec.message for rec in caplog.records] + +Live Logs +^^^^^^^^^ + +By default, pytest will output any logging records with a level higher or +equal to WARNING. In order to actually see these logs in the console you have to +disable pytest output capture by passing ``-s``. + +You can specify the logging level for which log records with equal or higher +level are printed to the console by passing ``--log-cli-level``. This setting +accepts the logging level names as seen in python's documentation or an integer +as the logging level num. + +Additionally, you can also specify ``--log-cli-format`` and +``--log-cli-date-format`` which mirror and default to ``--log-format`` and +``--log-date-format`` if not provided, but are applied only to the console +logging handler. + +All of the CLI log options can also be set in the configuration INI file. The +option names are: + +* ``log_cli_level`` +* ``log_cli_format`` +* ``log_cli_date_format`` + +If you need to record the whole test suite logging calls to a file, you can pass +``--log-file=/path/to/log/file``. This log file is opened in write mode which +means that it will be overwritten at each run tests session. + +You can also specify the logging level for the log file by passing +``--log-file-level``. This setting accepts the logging level names as seen in +python's documentation(ie, uppercased level names) or an integer as the logging +level num. + +Additionally, you can also specify ``--log-file-format`` and +``--log-file-date-format`` which are equal to ``--log-format`` and +``--log-date-format`` but are applied to the log file logging handler. + +All of the log file options can also be set in the configuration INI file. The +option names are: + +* ``log_file`` +* ``log_file_level`` +* ``log_file_format`` +* ``log_file_date_format`` diff --git a/doc/en/plugins.rst b/doc/en/plugins.rst index ec031e9e0..bba7d3ecd 100644 --- a/doc/en/plugins.rst +++ b/doc/en/plugins.rst @@ -27,9 +27,6 @@ Here is a little annotated list for some popular plugins: for `twisted <http://twistedmatrix.com>`_ apps, starting a reactor and processing deferreds from test functions. -* `pytest-catchlog <http://pypi.python.org/pypi/pytest-catchlog>`_: - to capture and assert about messages from the logging module - * `pytest-cov <http://pypi.python.org/pypi/pytest-cov>`_: coverage reporting, compatible with distributed testing diff --git a/doc/en/usage.rst b/doc/en/usage.rst index a8c6d40a0..1cb64ec87 100644 --- a/doc/en/usage.rst +++ b/doc/en/usage.rst @@ -189,7 +189,6 @@ in your code and pytest automatically disables its output capture for that test: for test output occurring after you exit the interactive PDB_ tracing session and continue with the regular test run. - .. _durations: Profiling test execution duration If completing this task requires creating new files, classes, fields, or error messages, you may consider using the following suggested entity names: [{'type': 'file', 'name': '_pytest/logging.py'}, {'type': 'field', 'name': 'ret'}]
matplotlib/matplotlib
matplotlib__matplotlib-18715
https://github.com/matplotlib/matplotlib/pull/18715
diff --git a/doc/users/next_whats_new/auto_minor_tick.rst b/doc/users/next_whats_new/auto_minor_tick.rst new file mode 100644 index 000000000000..02db8f6beb38 --- /dev/null +++ b/doc/users/next_whats_new/auto_minor_tick.rst @@ -0,0 +1,5 @@ +rcParams for ``AutoMinorLocator`` divisions +------------------------------------------- +The rcParams :rc:`xtick.minor.ndivs` and :rc:`ytick.minor.ndivs` have been +added to enable setting the default number of divisions; if set to ``auto``, +the number of divisions will be chosen by the distance between major ticks. diff --git a/lib/matplotlib/mpl-data/matplotlibrc b/lib/matplotlib/mpl-data/matplotlibrc index 578777167d6c..86f70a23dacd 100644 --- a/lib/matplotlib/mpl-data/matplotlibrc +++ b/lib/matplotlib/mpl-data/matplotlibrc @@ -489,6 +489,7 @@ #xtick.major.bottom: True # draw x axis bottom major ticks #xtick.minor.top: True # draw x axis top minor ticks #xtick.minor.bottom: True # draw x axis bottom minor ticks +#xtick.minor.ndivs: auto # number of minor ticks between the major ticks on x-axis #xtick.alignment: center # alignment of xticks #ytick.left: True # draw ticks on the left side @@ -510,6 +511,7 @@ #ytick.major.right: True # draw y axis right major ticks #ytick.minor.left: True # draw y axis left minor ticks #ytick.minor.right: True # draw y axis right minor ticks +#ytick.minor.ndivs: auto # number of minor ticks between the major ticks on y-axis #ytick.alignment: center_baseline # alignment of yticks diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index b27ac35bcb4d..663ff4b70536 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -568,6 +568,14 @@ def _validate_greaterequal0_lessequal1(s): raise RuntimeError(f'Value must be >=0 and <=1; got {s}') +def _validate_int_greaterequal0(s): + s = validate_int(s) + if s >= 0: + return s + else: + raise RuntimeError(f'Value must be >=0; got {s}') + + def validate_hatch(s): r""" Validate a hatch pattern. @@ -587,6 +595,24 @@ def validate_hatch(s): validate_dashlist = _listify_validator(validate_floatlist) +def _validate_minor_tick_ndivs(n): + """ + Validate ndiv parameter related to the minor ticks. + It controls the number of minor ticks to be placed between + two major ticks. + """ + + if isinstance(n, str) and n.lower() == 'auto': + return n + try: + n = _validate_int_greaterequal0(n) + return n + except (RuntimeError, ValueError): + pass + + raise ValueError("'tick.minor.ndivs' must be 'auto' or non-negative int") + + _prop_validators = { 'color': _listify_validator(validate_color_for_prop_cycle, allow_stringlist=True), @@ -1093,6 +1119,8 @@ def _convert_validator_spec(key, conv): "xtick.minor.bottom": validate_bool, # draw bottom minor xticks "xtick.major.top": validate_bool, # draw top major xticks "xtick.major.bottom": validate_bool, # draw bottom major xticks + # number of minor xticks + "xtick.minor.ndivs": _validate_minor_tick_ndivs, "xtick.labelsize": validate_fontsize, # fontsize of xtick labels "xtick.direction": ["out", "in", "inout"], # direction of xticks "xtick.alignment": ["center", "right", "left"], @@ -1114,6 +1142,8 @@ def _convert_validator_spec(key, conv): "ytick.minor.right": validate_bool, # draw right minor yticks "ytick.major.left": validate_bool, # draw left major yticks "ytick.major.right": validate_bool, # draw right major yticks + # number of minor yticks + "ytick.minor.ndivs": _validate_minor_tick_ndivs, "ytick.labelsize": validate_fontsize, # fontsize of ytick labels "ytick.direction": ["out", "in", "inout"], # direction of yticks "ytick.alignment": [ diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index a29343029f60..bf059567f5fe 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2869,7 +2869,11 @@ def __init__(self, n=None): major ticks; e.g., n=2 will place a single minor tick midway between major ticks. - If *n* is omitted or None, it will be set to 5 or 4. + If *n* is omitted or None, the value stored in rcParams will be used. + In case *n* is set to 'auto', it will be set to 4 or 5. If the distance + between the major ticks equals 1, 2.5, 5 or 10 it can be perfectly + divided in 5 equidistant sub-intervals with a length multiple of + 0.05. Otherwise it is divided in 4 sub-intervals. """ self.ndivs = n @@ -2892,6 +2896,14 @@ def __call__(self): if self.ndivs is None: + if self.axis.axis_name == 'y': + self.ndivs = mpl.rcParams['ytick.minor.ndivs'] + else: + # for x and z axis + self.ndivs = mpl.rcParams['xtick.minor.ndivs'] + + if self.ndivs == 'auto': + majorstep_no_exponent = 10 ** (np.log10(majorstep) % 1) if np.isclose(majorstep_no_exponent, [1.0, 2.5, 5.0, 10.0]).any():
diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 15981c4c9047..3d38df575f09 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -211,6 +211,60 @@ def test_additional(self, lim, ref): assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) + @pytest.mark.parametrize('use_rcparam', [False, True]) + @pytest.mark.parametrize( + 'lim, ref', [ + ((0, 1.39), + [0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, 0.5, 0.55, 0.65, 0.7, + 0.75, 0.85, 0.9, 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35]), + ((0, 0.139), + [0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, 0.05, 0.055, + 0.065, 0.07, 0.075, 0.085, 0.09, 0.095, 0.105, 0.11, 0.115, + 0.125, 0.13, 0.135]), + ]) + def test_number_of_minor_ticks_auto(self, lim, ref, use_rcparam): + if use_rcparam: + context = {'xtick.minor.ndivs': 'auto', 'ytick.minor.ndivs': 'auto'} + kwargs = {} + else: + context = {} + kwargs = {'n': 'auto'} + + with mpl.rc_context(context): + fig, ax = plt.subplots() + ax.set_xlim(*lim) + ax.set_ylim(*lim) + ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs)) + ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs)) + assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref) + assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) + + @pytest.mark.parametrize('use_rcparam', [False, True]) + @pytest.mark.parametrize( + 'n, lim, ref', [ + (2, (0, 4), [0.5, 1.5, 2.5, 3.5]), + (4, (0, 2), [0.25, 0.5, 0.75, 1.25, 1.5, 1.75]), + (10, (0, 1), [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]), + ]) + def test_number_of_minor_ticks_int(self, n, lim, ref, use_rcparam): + if use_rcparam: + context = {'xtick.minor.ndivs': n, 'ytick.minor.ndivs': n} + kwargs = {} + else: + context = {} + kwargs = {'n': n} + + with mpl.rc_context(context): + fig, ax = plt.subplots() + ax.set_xlim(*lim) + ax.set_ylim(*lim) + ax.xaxis.set_major_locator(mticker.MultipleLocator(1)) + ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs)) + ax.yaxis.set_major_locator(mticker.MultipleLocator(1)) + ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs)) + assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref) + assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) + class TestLogLocator: def test_basic(self):
[ { "path": "doc/users/next_whats_new/auto_minor_tick.rst", "old_path": "/dev/null", "new_path": "b/doc/users/next_whats_new/auto_minor_tick.rst", "metadata": "diff --git a/doc/users/next_whats_new/auto_minor_tick.rst b/doc/users/next_whats_new/auto_minor_tick.rst\nnew file mode 100644\nindex 000000000000..02db8f6beb38\n--- /dev/null\n+++ b/doc/users/next_whats_new/auto_minor_tick.rst\n@@ -0,0 +1,5 @@\n+rcParams for ``AutoMinorLocator`` divisions\n+-------------------------------------------\n+The rcParams :rc:`xtick.minor.ndivs` and :rc:`ytick.minor.ndivs` have been\n+added to enable setting the default number of divisions; if set to ``auto``,\n+the number of divisions will be chosen by the distance between major ticks.\n", "update": null } ]
3.7
b61bb0b6392c23d38cd45c658bfcd44df145830d
[ "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1000-100-1000]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[-0.492-0.492-0]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[autodecimal, x<100%, display_range=8.4 (autodecimal test 2)]", "lib/matplotlib/tests/test_ticker.py::TestMultipleLocator::test_view_limits_round_numbers", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.001-0.015-0.001]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_cursor_dummy_axis[0.0123-0.012]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_invalid[-0.1]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-1001-expected21]", "lib/matplotlib/tests/test_ticker.py::TestAsinhLocator::test_linear_values", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_minor[lims6-expected_low_ticks6]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_format_data[0.1-1e-1]", "lib/matplotlib/tests/test_ticker.py::TestFormatStrFormatter::test_basic", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_format_data_short[253]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims0]", "lib/matplotlib/tests/test_ticker.py::TestLogLocator::test_tick_values_not_empty", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterMathtext::test_min_exponent[3-1000.0-$\\\\mathdefault{10^{3}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.003141592654-100-0]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_variablelength[0.02005753653785041]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.003141592654-0.001-3.142e-3]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.1-0.001-1e-1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1000-0.015-1000]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.001]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.01-0.001-1e-2]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims8]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_invalid[-1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterMathtext::test_min_exponent[0-1-$\\\\mathdefault{10^{0}}$]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[False--1234.56789-expected0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[2.718281828459045-False-50-locs2-positions2-expected2]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True--999.9999-expected19]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.3141592654-0.015-0.314]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_variablelength[0.9956983447069072]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_minor_vs_major[False-lims3-cases3]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_latex[True-True-50\\\\{t}%]", "lib/matplotlib/tests/test_ticker.py::TestMaxNLocator::test_basic[0.001-0.0001-expected1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1000-0.001-1000]", "lib/matplotlib/tests/test_ticker.py::test_small_range_loglocator[9]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[5.0-False-50-locs2-positions2-expected2]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[5.0-False-10-locs1-positions1-expected1]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[decimals=0, x>100%]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.3141592654-100-0.3]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[autodecimal, x<-100%, display_range=1e-6 (tiny display range)]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterMathtext::test_min_exponent[3-100.0-$\\\\mathdefault{100}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1-0.015-1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[10-500000-$\\\\mathdefault{5\\\\times10^{5}}$]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_format_data[0.11-1.1e-1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[3.141592653589793-False-10-locs1-positions1-expected1]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.1]", "lib/matplotlib/tests/test_ticker.py::TestFixedLocator::test_set_params", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims3]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[autodecimal, x>100%, display_range=6 (custom xmax test)]", "lib/matplotlib/tests/test_ticker.py::TestAsinhLocator::test_symmetrizing", "lib/matplotlib/tests/test_ticker.py::TestSymmetricalLogLocator::test_set_params", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_cursor_dummy_axis[0.0-0.000]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims11]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims26]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100-100-100]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_unicode_minus[False--1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[3.141592653589793-True-4-locs0-positions0-expected0]", "lib/matplotlib/tests/test_ticker.py::TestLogLocator::test_switch_to_autolocator", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_basic_major[lims1-expected_low_ticks1]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_logit_deformater[STUFF0.41OTHERSTUFF-0.41]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[1e-07]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True--0.00123456789-expected7]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[autodecimal, x<100%, display_range=1]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_basic", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.1-0.015-0.1]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[3789.12-3783.1-3780]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.03141592654-0.5-0.031]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.999999999]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterMathtext::test_min_exponent[0-100.0-$\\\\mathdefault{10^{2}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654-1000000.0-3.1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100-1000000.0-100]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_sublabel", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.01-5-0.01]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0003141592654-0.015-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0001-1000000.0-1e-4]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_scilimits[True-scilimits8-lim8-6-False]", "lib/matplotlib/tests/test_ticker.py::TestLogLocator::test_tick_values_correct", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_scilimits[True-scilimits2-lim2-0-False]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_LogFormatter_call[1000]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0003141592654-5-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[10-100000-$\\\\mathdefault{10^{5}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0001-100-0]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_variablelength[0.0009110511944006454]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_empty_locs", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_basic_major[lims5-expected_low_ticks5]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314159.2654-0.5-314159.265]", "lib/matplotlib/tests/test_ticker.py::TestMultipleLocator::test_set_params", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_scilimits[True-scilimits4-lim4-2-False]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[0.99-1.01-1]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks_int[10-lim2-ref2-False]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[Custom percent symbol]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_logit_deformater[STUFF-None]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31.41592654-0.001-3.142e1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31.41592654-0.5-31.416]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_logit_deformater[STUFF1-0.41OTHERSTUFF-0.5900000000000001]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.3141592654-0.5-0.314]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[-0.452-0.492-0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_use_locale", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims5]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims18]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims20]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_variablelength[0.08839967720705845]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314159.2654-5-314159.27]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.003141592654-0.5-0.003]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_basic_major[lims2-expected_low_ticks2]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[decimals=1, x=100%]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_variablelength[0.6852009766653157]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_latex[True-False-50\\\\{t}%]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_maxn_major[lims2]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.9999]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-1.23456789-expected15]", "lib/matplotlib/tests/test_ticker.py::TestAsinhLocator::test_base_rounding", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_first_and_last_minorticks", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nbins_major[lims3]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-0.123456789-expected12]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654e-05-0.5-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[10.0-False-10-locs1-positions1-expected1]", "lib/matplotlib/tests/test_ticker.py::test_set_offset_string[formatter0]", "lib/matplotlib/tests/test_ticker.py::test_minorticks_rc", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_use_offset[True]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10-1000000.0-10]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[123-189-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.03141592654-5-0.03]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_minor_vs_major[True-lims2-cases2]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_variablelength[0.3147990233346844]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[2.718281828459045-False-10-locs1-positions1-expected1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0003141592654-0.001-3.142e-4]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1e-05-5-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_LogFormatter_call_tiny[1e-323]", "lib/matplotlib/tests/test_ticker.py::TestAsinhLocator::test_near_zero", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100-0.015-100]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[2.0-False-10-locs1-positions1-expected1]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_latex[False-False-50\\\\{t}%]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_variablelength[0.0043016552930929]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.001-0.001-1e-3]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.9]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10-0.001-10]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims29]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0001-0.015-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[10-1e-05-$\\\\mathdefault{10^{-5}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10000-5-10000]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_blank", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10000-1000000.0-1e4]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31.41592654-100-31.4]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[False--1.23456789-expected2]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[1e-09]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_low_number_of_majorticks[0-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314.1592654-0.015-314.159]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_basic_major[lims4-expected_low_ticks4]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_minor_vs_major[True-lims1-cases1]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[autodecimal, x<100%, display_range=8.5 (autodecimal test 1)]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_additional[lim6-ref6]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_minor[lims4-expected_low_ticks4]", "lib/matplotlib/tests/test_ticker.py::TestMaxNLocator::test_integer[1-55-steps2-expected2]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.001-1000000.0-1e-3]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[10-5e-05-$\\\\mathdefault{5\\\\times10^{-5}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims10]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.99999]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100-5-100]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-1.23e+33-expected24]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_format_data[110000000.0-1.1e8]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[2-0.0375-$\\\\mathdefault{1.2\\\\times2^{-5}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_variablelength[0.9116003227929417]", "lib/matplotlib/tests/test_ticker.py::test_majformatter_type", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True--1234.56789-expected1]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_scilimits[False-scilimits0-lim0-0-False]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10000-100-10000]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_variablelength[0.9990889488055994]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[10-2e-05-$\\\\mathdefault{2\\\\times10^{-5}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[5.0-True-4-locs0-positions0-expected0]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_nok[0.84]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims16]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[decimals=0, x=100%]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims21]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.1-100-0.1]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-1000-expected20]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.03141592654-0.001-3.142e-2]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims15]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.5]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-1.23456789e-06-expected11]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_using_all_default_major_steps", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[decimals=1, x<100%]", "lib/matplotlib/tests/test_ticker.py::TestMultipleLocator::test_basic", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[3.141592653589793-False-50-locs2-positions2-expected2]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims27]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.01-0.015-0.01]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.003141592654-5-0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[12341-12349-12340]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nbins_major[lims0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[10-5-$\\\\mathdefault{5\\\\times10^{0}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[1e-05]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31.41592654-1000000.0-3.1e1]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[1900.0-1200.0-0]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims23]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[10--1-$\\\\mathdefault{-10^{0}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.01-100-0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_useMathText[False]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_invalid[2]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_minor_vs_major[True-lims0-cases0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[0.4538-0.4578-0.45]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks[10-5]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-100001-expected22]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims6]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314159.2654-1000000.0-3.1e5]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314159.2654-0.001-3.142e5]", "lib/matplotlib/tests/test_ticker.py::TestAsinhLocator::test_fallback", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims12]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterMathtext::test_min_exponent[3-1-$\\\\mathdefault{1}$]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-0-expected10]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.99999999]", "lib/matplotlib/tests/test_ticker.py::test_minformatter_type", "lib/matplotlib/tests/test_ticker.py::TestMaxNLocator::test_basic[20-100-expected0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_use_offset[False]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[False--0.00123456789-expected6]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_cursor_precision[0.0-0.000]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_basic_major[lims0-expected_low_ticks0]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-0-expected9]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[123-123-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterMathtext::test_min_exponent[3-0.01-$\\\\mathdefault{0.01}$]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[-189--123-0]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nbins_major[lims1]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_additional[lim0-ref0]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[decimals=1, x<0%]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10-0.5-10]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_cursor_precision[0.0123-0.012]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_useMathText[True]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[1e-08]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31415.92654-0.5-31415.927]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_invalid[1.5]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_format_data_short[754]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1e-05-0.5-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.1-1000000.0-1e-1]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_cursor_precision[12.3-12.300]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10-100-10]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_nok[0.9359999999999999]", "lib/matplotlib/tests/test_ticker.py::TestAsinhLocator::test_wide_values", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_scilimits[True-scilimits1-lim1-0-False]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nbins_major[lims4]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_basic_major[lims3-expected_low_ticks3]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[10-200000-$\\\\mathdefault{2\\\\times10^{5}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims17]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314.1592654-1000000.0-3.1e2]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0001-5-0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[99990.5-100000.5-100000]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1-5-1]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_unicode_minus[True-\\u22121]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314.1592654-5-314.16]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100-0.001-100]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-1-expected14]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.03141592654-1000000.0-3.1e-2]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10000-0.001-1e4]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_minor[lims7-expected_low_ticks7]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[-100010.5--99999.5--100000]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_minor[lims3-expected_low_ticks3]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_logit_deformater[STUFF12.4e-3OTHERSTUFF-None]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nbins_major[lims10]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.01-1000000.0-1e-2]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1000-5-1000]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims13]", "lib/matplotlib/tests/test_ticker.py::test_remove_overlap[False-9]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterMathtext::test_min_exponent[0-0.01-$\\\\mathdefault{10^{-2}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims25]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_cmr10_substitutions", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10000-0.5-10000]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.001-100-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[2.0-False-50-locs2-positions2-expected2]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3141.592654-0.015-3141.593]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654-0.015-3.142]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_LogFormatter_call[100]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[-12335.3-12335.3-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1-100-1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1e-05-0.015-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterMathtext::test_min_exponent[3-0.001-$\\\\mathdefault{10^{-3}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31.41592654-5-31.42]", "lib/matplotlib/tests/test_ticker.py::TestMaxNLocator::test_basic[-8.5e-51-0-expected4]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims28]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nbins_major[lims6]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654e-05-1000000.0-3.1e-5]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100-0.5-100]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654e-05-5-0]", "lib/matplotlib/tests/test_ticker.py::TestMultipleLocator::test_view_limits", "lib/matplotlib/tests/test_ticker.py::test_remove_overlap[None-6]", "lib/matplotlib/tests/test_ticker.py::TestStrMethodFormatter::test_basic[{x:05d}-input0-00002]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.01]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_cursor_precision[0.123-0.123]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims19]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0003141592654-100-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1000-1000000.0-1000]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[2-0.03125-$\\\\mathdefault{2^{-5}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654e-05-0.001-3.142e-5]", "lib/matplotlib/tests/test_ticker.py::test_small_range_loglocator[1]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims4]", "lib/matplotlib/tests/test_ticker.py::TestAsinhLocator::test_init", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314159.2654-100-314159.3]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314159.2654-0.015-314159.265]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10000-0.015-10000]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks[1-5]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10-5-10]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_format_data[100000000.0-1e8]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[10-0.015-10]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_invalid[-0.5]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[2-32-$\\\\mathdefault{2^{5}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3141.592654-100-3141.6]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[2-1.2-$\\\\mathdefault{1.2\\\\times2^{0}}$]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_set_use_offset_float", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[2.718281828459045-True-4-locs0-positions0-expected0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[10-1-$\\\\mathdefault{10^{0}}$]", "lib/matplotlib/tests/test_ticker.py::test_bad_locator_subs[sub1]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_use_overline", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100000-100-100000]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_logit_deformater[STUFF1-1.41\\\\cdot10^{-2}OTHERSTUFF-0.9859]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31415.92654-1000000.0-3.1e4]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100000-0.001-1e5]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31415.92654-5-31415.93]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks_int[2-lim0-ref0-False]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_maxn_major[lims0]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks_int[4-lim1-ref1-False]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_LogFormatter_call[10]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_additional[lim4-ref4]", "lib/matplotlib/tests/test_ticker.py::TestAsinhLocator::test_set_params", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[decimals=0, x<100%]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_minor[lims5-expected_low_ticks5]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31.41592654-0.015-31.416]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[900.0-1200.0-0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1-0.001-1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3141.592654-0.5-3141.593]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[2.0-True-4-locs0-positions0-expected0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100000-0.5-100000]", "lib/matplotlib/tests/test_ticker.py::test_locale_comma", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True--0.123456789-expected5]", "lib/matplotlib/tests/test_ticker.py::TestMaxNLocator::test_integer[-0.1-1.1-None-expected0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[1233999-1234001-1234000]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654e-05-0.015-0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[15.99-16.01-16]", "lib/matplotlib/tests/test_ticker.py::test_set_offset_string[formatter1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1-1000000.0-1]", "lib/matplotlib/tests/test_ticker.py::test_NullFormatter", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_nok[0.064]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nbins_major[lims8]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.99]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3141.592654-1000000.0-3.1e3]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_scilimits[True-scilimits6-lim6-9-True]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[10-2-$\\\\mathdefault{2\\\\times10^{0}}$]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-999.9999-expected17]", "lib/matplotlib/tests/test_ticker.py::test_engformatter_usetex_useMathText", "lib/matplotlib/tests/test_ticker.py::test_small_range_loglocator[2]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_scilimits[True-scilimits5-lim5--3-False]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_minor_number", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1-0.5-1]", "lib/matplotlib/tests/test_ticker.py::TestNullLocator::test_set_params", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.3141592654-5-0.31]", "lib/matplotlib/tests/test_ticker.py::TestLogLocator::test_set_params", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[decimals=0, x<0%]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_format_data_short[100]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[False--999.9999-expected18]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0003141592654-1000000.0-3.1e-4]", "lib/matplotlib/tests/test_ticker.py::TestMaxNLocator::test_basic[0-8.5e-51-expected3]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3141.592654-0.001-3.142e3]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.3141592654-0.001-3.142e-1]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims2]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_one_half", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[10.0-False-50-locs2-positions2-expected2]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654-0.001-3.142]", "lib/matplotlib/tests/test_ticker.py::test_small_range_loglocator[3]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_basic_major[lims7-expected_low_ticks7]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_logit_deformater[STUFF1.41\\\\cdot10^{-2}OTHERSTUFF-0.0141]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.999]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.001-5-0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[9.99-10.01-10]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0001-0.5-0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[12331.4-12350.5-12300]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[False--0.123456789-expected4]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3141.592654-5-3141.59]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_additional[lim3-ref3]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[Empty percent symbol]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0003141592654-0.5-0]", "lib/matplotlib/tests/test_ticker.py::test_majlocator_type", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.1-0.5-0.1]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_minor[lims2-expected_low_ticks2]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nbins_major[lims5]", "lib/matplotlib/tests/test_ticker.py::test_bad_locator_subs[sub0]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nbins_major[lims9]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.1-5-0.1]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nbins_major[lims2]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.0001-0.001-1e-4]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.3141592654-1000000.0-3.1e-1]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[None as percent symbol]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1000-0.5-1000]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_minor[lims1-expected_low_ticks1]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_basic[decimals=1, x>100%]", "lib/matplotlib/tests/test_ticker.py::test_minlocator_type", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[45124.3-45831.75-45000]", "lib/matplotlib/tests/test_ticker.py::TestLogLocator::test_multiple_shared_axes", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_additional[lim7-ref7]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314.1592654-0.001-3.142e2]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654-5-3.14]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-0.1-expected13]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[-100000.5--99990.5--100000]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_cursor_dummy_axis[12.3-12.300]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks[2.5-5]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_maxn_major[lims1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1e-05-0.001-1e-5]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_nok[0.6000000000000001]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_cursor_dummy_axis[1.23-1.230]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[99.99-100.01-100]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.999999]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.03141592654-0.015-0.031]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims7]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_scilimits[True-scilimits7-lim7-5-False]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims14]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims1]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_additional[lim2-ref2]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_nok[0.39999999999999997]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_cursor_precision[1.23-1.230]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654-100-3.1]", "lib/matplotlib/tests/test_ticker.py::TestMaxNLocator::test_basic[-1000000000000000.0-1000000000000000.0-expected2]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_additional[lim5-ref5]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_nok[0.16]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[12592.82-12591.43-12590]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.9999999]", "lib/matplotlib/tests/test_ticker.py::test_remove_overlap[True-6]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[9.0-12.0-0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[1-1-1]", "lib/matplotlib/tests/test_ticker.py::TestLogLocator::test_polar_axes", "lib/matplotlib/tests/test_ticker.py::TestLogLocator::test_basic", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31415.92654-0.001-3.142e4]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1e-05-1000000.0-1e-5]", "lib/matplotlib/tests/test_ticker.py::TestLinearLocator::test_set_params", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks[2-4]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[2-38.4-$\\\\mathdefault{1.2\\\\times2^{5}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654e-05-100-0]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_scilimits[True-scilimits3-lim3-2-False]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[-12349--12341--12340]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims24]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[99999.5-100010.5-100000]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True--0.0-expected8]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[3.141592654-0.5-3.142]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.001-0.5-0.001]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterExponent::test_basic[10.0-True-4-locs0-positions0-expected0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_LogFormatter_call[1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.03141592654-100-0]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_basic_major[lims6-expected_low_ticks6]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims22]", "lib/matplotlib/tests/test_ticker.py::TestMaxNLocator::test_integer[-0.1-0.95-None-expected1]", "lib/matplotlib/tests/test_ticker.py::TestIndexLocator::test_set_params", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nbins_major[lims7]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_low_number_of_majorticks[1-0]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_minor_attr", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100000-1000000.0-1e5]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks[5-5]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[1e-05-100-0]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_variablelength[0.9799424634621495]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.003141592654-0.015-0.003]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31415.92654-100-31415.9]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-999.9-expected16]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_LogFormatter_call_tiny[2e-323]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True--1.23456789-expected3]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_nonsingular_ok[lims9]", "lib/matplotlib/tests/test_ticker.py::TestLogitLocator::test_minor[lims0-expected_low_ticks0]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314.1592654-0.5-314.159]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_LogFormatter_call_tiny[1.1e-322]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_additional[lim1-ref1]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[0.000721-0.0007243-0.00072]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_cursor_dummy_axis[0.123-0.123]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[1e-06]", "lib/matplotlib/tests/test_ticker.py::TestPercentFormatter::test_latex[False-True-50\\\\\\\\\\\\{t\\\\}\\\\%]", "lib/matplotlib/tests/test_ticker.py::TestStrMethodFormatter::test_basic[{x:03d}-{pos:02d}-input1-002-01]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.003141592654-1000000.0-3.1e-3]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_LogFormatter_call_tiny[1e-322]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[31415.92654-0.015-31415.927]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_invalid[1.1]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[314.1592654-100-314.2]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatterSciNotation::test_basic[2-1-$\\\\mathdefault{2^{0}}$]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[0.01-0.5-0.01]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100000-5-100000]", "lib/matplotlib/tests/test_ticker.py::TestLogitFormatter::test_basic[0.0001]", "lib/matplotlib/tests/test_ticker.py::TestLinearLocator::test_basic", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[-1234001--1233999--1234000]", "lib/matplotlib/tests/test_ticker.py::TestEngFormatter::test_params[True-987654.321-expected23]", "lib/matplotlib/tests/test_ticker.py::TestScalarFormatter::test_offset_value[5.99-6.01-6]", "lib/matplotlib/tests/test_ticker.py::TestLogFormatter::test_pprint[100000-0.015-100000]" ]
[ "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks_int[2-lim0-ref0-True]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks_auto[lim1-ref1-False]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks_auto[lim1-ref1-True]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks_int[4-lim1-ref1-True]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks_auto[lim0-ref0-True]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks_int[10-lim2-ref2-True]", "lib/matplotlib/tests/test_ticker.py::TestAutoMinorLocator::test_number_of_minor_ticks_auto[lim0-ref0-False]" ]
[ { "path": "doc/users/next_whats_new/auto_minor_tick.rst", "old_path": "/dev/null", "new_path": "b/doc/users/next_whats_new/auto_minor_tick.rst", "metadata": "diff --git a/doc/users/next_whats_new/auto_minor_tick.rst b/doc/users/next_whats_new/auto_minor_tick.rst\nnew file mode 100644\nindex 0000000000..02db8f6beb\n--- /dev/null\n+++ b/doc/users/next_whats_new/auto_minor_tick.rst\n@@ -0,0 +1,5 @@\n+rcParams for ``AutoMinorLocator`` divisions\n+-------------------------------------------\n+The rcParams :rc:`xtick.minor.ndivs` and :rc:`ytick.minor.ndivs` have been\n+added to enable setting the default number of divisions; if set to ``auto``,\n+the number of divisions will be chosen by the distance between major ticks.\n" } ]
{ "header": "If completing this task requires creating new files, classes, fields, or error messages, you may consider using the following suggested entity names:", "data": [] }
diff --git a/doc/users/next_whats_new/auto_minor_tick.rst b/doc/users/next_whats_new/auto_minor_tick.rst new file mode 100644 index 0000000000..02db8f6beb --- /dev/null +++ b/doc/users/next_whats_new/auto_minor_tick.rst @@ -0,0 +1,5 @@ +rcParams for ``AutoMinorLocator`` divisions +------------------------------------------- +The rcParams :rc:`xtick.minor.ndivs` and :rc:`ytick.minor.ndivs` have been +added to enable setting the default number of divisions; if set to ``auto``, +the number of divisions will be chosen by the distance between major ticks.
matplotlib/matplotlib
matplotlib__matplotlib-19743
https://github.com/matplotlib/matplotlib/pull/19743
"diff --git a/doc/users/next_whats_new/legend-figure-outside.rst b/doc/users/next_whats_new/legend-f(...TRUNCATED)
"diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py\nindex 56794(...TRUNCATED)
[{"path":"doc/users/next_whats_new/legend-figure-outside.rst","old_path":"/dev/null","new_path":"b/d(...TRUNCATED)
3.5
5793ebb2201bf778f08ac1d4cd0b8dd674c96053
["lib/matplotlib/tests/test_legend.py::test_legend_auto1[png]","lib/matplotlib/tests/test_legend.py:(...TRUNCATED)
[ "lib/matplotlib/tests/test_legend.py::test_figure_legend_outside" ]
[{"path":"doc/users/next_whats_new/legend-figure-outside.rst","old_path":"/dev/null","new_path":"b/d(...TRUNCATED)
{"header":"If completing this task requires creating new files, classes, fields, or error messages, (...TRUNCATED)
"diff --git a/doc/users/next_whats_new/legend-figure-outside.rst b/doc/users/next_whats_new/legend-f(...TRUNCATED)
matplotlib/matplotlib
matplotlib__matplotlib-23525
https://github.com/matplotlib/matplotlib/pull/23525
"diff --git a/doc/users/next_whats_new/bar_plot_labels.rst b/doc/users/next_whats_new/bar_plot_label(...TRUNCATED)
"diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py\nindex 51fbea3cf(...TRUNCATED)
[{"path":"doc/users/next_whats_new/bar_plot_labels.rst","old_path":"/dev/null","new_path":"b/doc/use(...TRUNCATED)
3.5
23100c42b274898f983011c12d5399a96982fe71
["lib/matplotlib/tests/test_axes.py::test_stem_dates","lib/matplotlib/tests/test_axes.py::test_error(...TRUNCATED)
["lib/matplotlib/tests/test_axes.py::test_bar_labels[x1-width1-label1-expected_labels1-_nolegend_]",(...TRUNCATED)
[{"path":"doc/users/next_whats_new/bar_plot_labels.rst","old_path":"/dev/null","new_path":"b/doc/use(...TRUNCATED)
{"header":"If completing this task requires creating new files, classes, fields, or error messages, (...TRUNCATED)
"diff --git a/doc/users/next_whats_new/bar_plot_labels.rst b/doc/users/next_whats_new/bar_plot_label(...TRUNCATED)
matplotlib/matplotlib
matplotlib__matplotlib-24470
https://github.com/matplotlib/matplotlib/pull/24470
"diff --git a/doc/users/next_whats_new/pie_hatch.rst b/doc/users/next_whats_new/pie_hatch.rst\nnew f(...TRUNCATED)
"diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py\nindex 3b471d4e0(...TRUNCATED)
[{"path":"doc/users/next_whats_new/pie_hatch.rst","old_path":"/dev/null","new_path":"b/doc/users/nex(...TRUNCATED)
3.5
e0dc18d51ef29118cc13e394f76641dcb5198846
["lib/matplotlib/tests/test_axes.py::test_stem_dates","lib/matplotlib/tests/test_axes.py::test_error(...TRUNCATED)
["lib/matplotlib/tests/test_axes.py::test_pie_hatch_multi[pdf]","lib/matplotlib/tests/test_axes.py::(...TRUNCATED)
[{"path":"doc/users/next_whats_new/pie_hatch.rst","old_path":"/dev/null","new_path":"b/doc/users/nex(...TRUNCATED)
{"header":"If completing this task requires creating new files, classes, fields, or error messages, (...TRUNCATED)
"diff --git a/doc/users/next_whats_new/pie_hatch.rst b/doc/users/next_whats_new/pie_hatch.rst\nnew f(...TRUNCATED)
matplotlib/matplotlib
matplotlib__matplotlib-24937
https://github.com/matplotlib/matplotlib/pull/24937
"diff --git a/doc/users/next_whats_new/pie_hatch.rst b/doc/users/next_whats_new/pie_hatch.rst\nnew f(...TRUNCATED)
"diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py\nindex f3f6b8938(...TRUNCATED)
[{"path":"doc/users/next_whats_new/pie_hatch.rst","old_path":"/dev/null","new_path":"b/doc/users/nex(...TRUNCATED)
3.5
c19b6f5e9dc011c3b31d9996368c0fea4dcd3594
["lib/matplotlib/tests/test_axes.py::test_stem_dates","lib/matplotlib/tests/test_axes.py::test_error(...TRUNCATED)
["lib/matplotlib/tests/test_axes.py::test_pie_hatch_multi[pdf]","lib/matplotlib/tests/test_axes.py::(...TRUNCATED)
[{"path":"doc/users/next_whats_new/pie_hatch.rst","old_path":"/dev/null","new_path":"b/doc/users/nex(...TRUNCATED)
{"header":"If completing this task requires creating new files, classes, fields, or error messages, (...TRUNCATED)
"diff --git a/doc/users/next_whats_new/pie_hatch.rst b/doc/users/next_whats_new/pie_hatch.rst\nnew f(...TRUNCATED)
matplotlib/matplotlib
matplotlib__matplotlib-20966
https://github.com/matplotlib/matplotlib/pull/20966
"diff --git a/doc/users/next_whats_new/callbacks_on_norms.rst b/doc/users/next_whats_new/callbacks_o(...TRUNCATED)
"diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py\nindex ae004(...TRUNCATED)
[{"path":"doc/users/next_whats_new/callbacks_on_norms.rst","old_path":"/dev/null","new_path":"b/doc/(...TRUNCATED)
3.4
1dff078a4645666af374dc55812788d37bea7612
["lib/matplotlib/tests/test_colors.py::test_colormap_reversing[OrRd_r]","lib/matplotlib/tests/test_c(...TRUNCATED)
["lib/matplotlib/tests/test_colors.py::test_norm_callback","lib/matplotlib/tests/test_colors.py::tes(...TRUNCATED)
[{"path":"doc/users/next_whats_new/callbacks_on_norms.rst","old_path":"/dev/null","new_path":"b/doc/(...TRUNCATED)
{"header":"If completing this task requires creating new files, classes, fields, or error messages, (...TRUNCATED)
"diff --git a/doc/users/next_whats_new/callbacks_on_norms.rst b/doc/users/next_whats_new/callbacks_o(...TRUNCATED)
matplotlib/matplotlib
matplotlib__matplotlib-20816
https://github.com/matplotlib/matplotlib/pull/20816
"diff --git a/doc/users/next_whats_new/callback_blocking.rst b/doc/users/next_whats_new/callback_blo(...TRUNCATED)
"diff --git a/lib/matplotlib/tests/test_cbook.py b/lib/matplotlib/tests/test_cbook.py\nindex 4728752(...TRUNCATED)
[{"path":"doc/users/next_whats_new/callback_blocking.rst","old_path":"/dev/null","new_path":"b/doc/u(...TRUNCATED)
3.4
586fcffaae03e40f851c5bc854de290b89bae18e
["lib/matplotlib/tests/test_cbook.py::test_normalize_kwargs_pass[inp1-expected1-kwargs_to_norm1]","l(...TRUNCATED)
[ "lib/matplotlib/tests/test_cbook.py::test_callbackregistry_blocking" ]
[{"path":"doc/users/next_whats_new/callback_blocking.rst","old_path":"/dev/null","new_path":"b/doc/u(...TRUNCATED)
{"header":"If completing this task requires creating new files, classes, fields, or error messages, (...TRUNCATED)
"diff --git a/doc/users/next_whats_new/callback_blocking.rst b/doc/users/next_whats_new/callback_blo(...TRUNCATED)
matplotlib/matplotlib
matplotlib__matplotlib-25686
https://github.com/matplotlib/matplotlib/pull/25686
"diff --git a/doc/users/next_whats_new/get_suptitle.rst b/doc/users/next_whats_new/get_suptitle.rst\(...TRUNCATED)
"diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py\nindex 4188c(...TRUNCATED)
[{"path":"doc/users/next_whats_new/get_suptitle.rst","old_path":"/dev/null","new_path":"b/doc/users/(...TRUNCATED)
3.7
b86ebbafe4673583345d0a01a6ea205af34c58dc
["lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_all_nested[png]","lib/matplotlib/test(...TRUNCATED)
[ "lib/matplotlib/tests/test_figure.py::test_get_suptitle_supxlabel_supylabel" ]
[{"path":"doc/users/next_whats_new/get_suptitle.rst","old_path":"/dev/null","new_path":"b/doc/users/(...TRUNCATED)
{"header":"If completing this task requires creating new files, classes, fields, or error messages, (...TRUNCATED)
"diff --git a/doc/users/next_whats_new/get_suptitle.rst b/doc/users/next_whats_new/get_suptitle.rst\(...TRUNCATED)
End of preview. Expand in Data Studio

Dataset Summary

NoCode-bench Verified is subset of NoCode-bench, a dataset that tests systems’ no-code feature addition ability automatically.

Languages

The text of the dataset is primarily English, but we make no effort to filter or otherwise clean based on language type.

Dataset Structure

An example of a SWE-bench datum is as follows:

repo: (str) - The repository owner/name identifier from GitHub.
instance_id: (str) - A formatted instance identifier, usually as repo_owner__repo_name-PR-number.
html_url: (str) - The URL of the PR web page where the instances are collected. 
feature_patch: (str) - The gold patch, the patch generated by the PR (minus test-related code), that resolved the issue.
test_patch: (str) - A test-file patch that was contributed by the solution PR.
doc_changes: (list) - The documentation changes in a certain PR.
version: (str) - Installation version to use for running evaluation.
base_commit: (str) - The commit hash of the repository representing the HEAD of the repository before the solution PR is applied.
PASS2PASS: (str) - A json list of strings that represent tests that should pass before and after the PR application.
FAIL2PASS: (str) - A json list of strings that represent the set of tests resolved by the PR and tied to the issue resolution.
augmentations: (dict) - A set of names of the entity used to implement the feature.
mask_doc_diff: (list) - The documentation changes in a certain PR, which masked the PR number.
problem_statement: (str) - The main input contained `mask_doc_diff` and `augmentations`.
Downloads last month
178