From 09be028ab5fd1b83d563f0e8d4b27aad733dfc48 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Sat, 29 Jun 2024 10:29:46 -0500 Subject: [PATCH 1/3] Show all warnings, including `ResourceWarning`, when testing The warnings are only displayed. They are not escalated to errors. --- tox.ini | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 9e7e52c..fba15df 100644 --- a/tox.ini +++ b/tox.ini @@ -15,8 +15,11 @@ deps = pytest pytest-cov pytest-icdiff +setenv = + # Display up to 20 frames in backtraces when showing ResourceWarnings. + PYTHONTRACEMALLOC=20 commands = - pytest --strict-markers --cov {posargs} + python -Wall -m pytest --strict-markers --cov {posargs} extras = md [testenv:mypy] From 342a7b2fc740202b050d1846ec38e20ba2ba2882 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Sat, 29 Jun 2024 10:30:13 -0500 Subject: [PATCH 2/3] Lazy-open output files, and ensure they are always closed --- readme_renderer/__main__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/readme_renderer/__main__.py b/readme_renderer/__main__.py index e7c1187..a370fab 100644 --- a/readme_renderer/__main__.py +++ b/readme_renderer/__main__.py @@ -18,7 +18,7 @@ def main(cli_args: Optional[List[str]] = None) -> None: help="README format (inferred from input file name or package)") parser.add_argument('input', help="Input README file or package name") parser.add_argument('-o', '--output', help="Output file (default: stdout)", - type=argparse.FileType('w'), default='-') + default='-') args = parser.parse_args(cli_args) content_format = args.format @@ -55,7 +55,11 @@ def main(cli_args: Optional[List[str]] = None) -> None: "`rst`, or `txt`)") if rendered is None: sys.exit(1) - print(rendered, file=args.output) + if args.output == "-": + print(rendered, file=sys.stdout) + else: + with open(args.output, "w") as fp: + print(rendered, file=fp) if __name__ == '__main__': From 3c42ccfbb1316b25d0796c499ec1e1af38b7b05a Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Sun, 7 Jul 2024 12:57:19 -0500 Subject: [PATCH 3/3] Feedback: Use `-Wall` argument with pytest, not Python --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index fba15df..4441a74 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ setenv = # Display up to 20 frames in backtraces when showing ResourceWarnings. PYTHONTRACEMALLOC=20 commands = - python -Wall -m pytest --strict-markers --cov {posargs} + pytest -Wall --strict-markers --cov {posargs} extras = md [testenv:mypy]