From 472ff3d7babea1a31d3daba48393389796482c98 Mon Sep 17 00:00:00 2001 From: Mark Taylor <24257134+tmarktaylor@users.noreply.github.com> Date: Fri, 15 Sep 2023 07:27:57 -0400 Subject: [PATCH] README.md update, cases.py reformat. Add dotted path details and run with pytest to README.md Removed commented out code from cases.py. --- README.md | 13 +++++++++++++ src/phmutest/cases.py | 7 ++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3d87d86..c8ae326 100644 --- a/README.md +++ b/README.md @@ -342,6 +342,17 @@ apply doctest optionflags in --replmode. Do patching cleanup when not in --replmode by calling `unittest.addModuleCleanup(stack.pop_all().close)`. +### Dotted path details + +The fixture function must be at the top level of a .py file. + +- The dotted_path has components separated by ".". +- The last component is the function name. +- The next to last component is the python file name without the .py suffix. +- The preceding components identify parent folders. Folders should be + relative to the current working directory which is typically the + project root. + ## Extend an example across files Names assigned by all the blocks in a file can be shared, as global variables, @@ -446,6 +457,8 @@ breakage in future versions. Look for examples in tests/test_patching.py. - In repl mode **no** skipped blocks are rendered. - Try redirecting `--generate -` standard output into PYPI Pygments to colorize the generated test file. +- pytest will run a generated test file (--generate TESTFILE). pytest won't + run functions added by unittest.addModuleCleanup(). ## Related projects diff --git a/src/phmutest/cases.py b/src/phmutest/cases.py index 3faa203..36c573d 100644 --- a/src/phmutest/cases.py +++ b/src/phmutest/cases.py @@ -331,17 +331,14 @@ def testfile(args: argparse.Namespace, block_store: phmutest.select.BlockStore) test_classes = "" replacements = {} if args.fixture: - # modulepackage, function_name = get_fixture_parts(args.fixture) - import_line = ( + replacements["importuserfixture"] = ( "from phmutest.importer import fixture_function_importer " "as _phm_fixture_function_importer" ) - replacements["importuserfixture"] = import_line - call_line = ( + replacements["calluserfixture"] = ( f"_phm_user_setup_function = " f'_phm_fixture_function_importer("{args.fixture}")' ) - replacements["calluserfixture"] = call_line if args.setup_across_files or args.share_across_files or args.fixture: setupcode = render_setup_module(args, block_store)