API: Test Support¶
test_support¶
This package includes helper code that is only used for testing setuptools-pyproject-migration
itself. The code is made available when testing by a
pytest configuration option
that extends sys.path.
- class test_support.Project(root: Path)¶
Bases:
objectA Python project on which
setup.py pyprojectcan be run. Test code should not normally construct instances ofProject()directly; instead, they can get one through a fixture or some helper function.Once you have the
Projectobject, create any files you need underneath the root by callingwrite()or one of its convenience wrappers likesetup_py()orsetup_cfg(). If you need to do anything other than creating files or if there is some reason not to use thewrite()method, you can work directly onroot, but don’t change anything outside ofroot. Finally, when all necessary files have been created, call one ofrun(),run_cli(), orgenerate()to runsetup.py pyproject(or an equivalent) on the project.- Parameters:
root – The root directory in which to create the project. It should already exist. Typically this might be a temporary directory created by pytest’s
tmp_pathfixture.
- distribution(*, extra_args: Iterable[str] | None = None) Distribution¶
Run
setup.pybut stop before actually executing any commands, and instead return theDistributionobject.
- generate(*, extra_args: Iterable[str] | None = None) Pyproject¶
Run the equivalent of
setup.py pyprojectbut return the generated data structure that would go into pyproject.toml instead of writing it out.
- run(runner: ProjectRunner, *, extra_args: Iterable[str] | None = None) ProjectRunResult¶
Run
setup.py pyprojecton the created project and return the output.If the project doesn’t already have a
setup.pyfile, a simple one will be automatically created by callingsetup_py()with no arguments before running it.- Parameters:
runner – The callable to use to run the script
- run_cli(runner: ProjectRunner, *, extra_args: Iterable[str] | None = None) ProjectRunResult¶
Run the console script
setuptools-pyproject-migrationon the created project and return the output.In contrast to
run(), ifsetup.pydoesn’t exist, it will not be created, because the script is supposed to work without it. If you want to test the script’s behavior with asetup.pyfile, create it “manually” with a call tosetup_py().- Parameters:
runner – The callable to use to run the script
- setup_cfg(content: str) None¶
Write a
setup.cfgfile in the project root directory.- Parameters:
content – Text content to write to the file.
- setup_py(content: str | None = None) None¶
Write a
setup.pyfile in the project root directory.- Parameters:
content – Text content to write to the file.
- write(filename: Path | str, content: str) None¶
Write a file with the given content and the given filename relative to the project root. If the file already exists, it will be overwritten after issuing a warning.
- Parameters:
filename – A filename or
pathlib.Pathrepresenting the file to write. This should be a relative path, which will be interpreted relative to the project root directory. If the referenced file is not inside the project root, a warning will be issued.content – Text content to write to the file.
- class test_support.ProjectRunner(*args, **kwargs)¶
Bases:
ProtocolA runner for an external command. This is basically an abstraction of
ScriptRunner.run()from pytest-console-scripts, or at least the subset of its behavior which we use in this project.