Skip to content

Commit

Permalink
README.md update, cases.py reformat.
Browse files Browse the repository at this point in the history
Add dotted path details and run with pytest to README.md Removed commented out code from cases.py.
  • Loading branch information
tmarktaylor committed Sep 15, 2023
1 parent 62b6362 commit 472ff3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
7 changes: 2 additions & 5 deletions src/phmutest/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 472ff3d

Please sign in to comment.