Package: pytest-git-fixtures
pytest-git-fixturesOverviewPytest fixtures to dynamically createGITrepositories for testing.Getting StartedUpdatesetup.pyto include:fromdistutils.coreimportsetupsetup(tests_require=["pytest-git-fixtures"])All fixtures should be automatically included via thepytest11entry point.importloggingimportsubprocessfrompytest_git_fixturesimportGITRepo# Optional, for typingLOGGER=logging.getLogger(__name__)deftest_sanity_check(git_repo:GITRepo):environment={"GNUPGHOME":git_repo.gnupg_keypair.gnupg_home,"HOME":str(git_repo.homedir),}completed_process=subprocess.run(["git","log","--show-signature"],capture_output=True,check=True,cwd=str(git_repo.clone_work_tree),env=environment,)stdout=completed_process.stdout.decode("utf-8")LOGGER.debug(stdout)assert"Good signature from"instdoutassertgit_repo.commit_messageinstdoutcompleted_process=subprocess.run(["git","log","--show-signature"],capture_output=True,check=True,cwd=str(git_repo.work_tree),env={**environment,**{"GIT_DIR":str(git_repo.upstream)}},)stdout=completed_process.stdout.decode("utf-8")LOGGER.debug(stdout)assert"Good signature from"instdoutassertgit_repo.commit_messageinstdoutTested with python 3.8InstallationFrompypi.org$ pip install pytest_git_fixturesFrom source code$gitclonehttps://github.com/crashvb/pytest-git-fixtures
$cdpytest-git-fixtures
$virtualenvenv
$sourceenv/bin/activate
$python-mpipinstall--editable.[dev]FixturesgitconfigProvides the path to a templated GIT configuration file that is used to initialize the repository. If a user-defined script (tests/gitconfig) can be located, it is used. Otherwise, an embedded configuration template is copied to temporary location and returned. This fixture is used by thegit_repofixture.TheGIT_USER_EMAIL,GIT_USER_NAME, andGIT_SIGNINGKEYvariables will be populated within the template during generation of the repository.git_commit_messageProvides the commit message of the initial commit to the repository. This fixture is used by thegit_repofixture.git_init_scriptProvides the path to a GIT initialization script that is used to create repository structure. If a user-defined script (tests/git-init.sh) can be located, it is used. Otherwise, an embedded script is copied to temporary location and returned. This fixture is used by thegit_repofixture.TheGIT_COMMIT_MESSAGE,GIT_INITIAL_BRANCH_NAME,GIT_PATH_CLONE,GIT_PATH_FORK,GIT_PATH_UPSTREAM,GIT_PATH_WORK_TREE,GIT_REMOTE_NAME_FORK,GIT_REMOTE_NAME_UPSTREAM,GIT_TEST_FILENAME,GIT_WORK_TREE_BRANCH_NAME,GNUPGHOME,GNUPG_PASSPHRASE, andHOMEenvironment variables will be populated during invocation of the script.git_initial_branch_name.Provides the name of the initial branch to use. This fixture is used by thegit_repofixture.git_remote_name_forkProvides the name of the remote used to reference the fork repository. This fixture is used by thegit_repofixture.git_remote_name_upstreamProvides the name of the remote used to reference the upstream repository. This fixture is used by thegit_repofixture.git_repoInitializes a temporary GIT repository with a bare upstream, fork, and separate work tree.NamedTuple FieldsThe following fields are defined in the tuple provided by this fixture:clone_git_dir- Path to the "clone" git-dir.clone_work_tree- Path to the "clone" work tree.commit_message- Commit message of the initial commit, created fromgit_commit_messagefork- Path to the "fork" git-dir.gitconfig- Path to the fully instantiated git configuration, created fromgitconfiggnupg- The GnuPG keypair used to sign commits, fromgnupg_keypairhomedir- Path to the home directory used to initialize the repo.initial_branch- Name of the initial branch, created fromgit_initial_branch_nameremote_fork- Name of the remote for the "fork", created fromgit_remote_name_forkremote_upstream- Name of the remote for the "upstream", created fromgit_remote_name_upstreamtest_filename- Name of the test file, created fromgit_test_filenameupstream- Path to the "upstream" git-dir.work_tree- Path to the separate "work tree" work tree.work_tree_branch- Name of the "work tree" branch, created fromgit_work_tree_branch_namework_tree_git_dir- Path to the "work tree" git-dir.Typing is provided bypytest_git_fixtures.GITRepo.git_test_filenameProvides the name of the test file committed into the repository. This fixture is used by thegit_repofixture.git_work_tree_branch_nameProvides the name of the branch used to create the git work tree. This fixture is used by thegit_repofixture.LimitationsThis has been coded to work with git-scm >= 2.6.The generated repository is very simple. TBD if this will be expanded to support a more realistic configuration.The embedded GIT configuration is configured to sign commits and tags by default. This can cause complications with externally configured instances of GnuPG, unless they are configured to use loopback for pinentry, or you like testing with interactive passphrase entry ;) . It is recommended thatpytest-gnupg-fixturesbe used. This package provides agpg-wrapperscript that can be used in conjunction with the gitgpg.programconfiguration value as follows:importsubprocessfrompytest_git_fixturesimportGITRepo# Optional, for typingdeftest_something_with_gnupg(git_repo:GITRepo):subprocess.run(["git","-c",f"gpg.program={git_repo.gnupg_keypair.gnupg_home}/gpg-wrapper","commit","--message","Look Ma, no hands!",],check=True,cwd=str(git_repo.clone_work_tree),env={"GNUPG_PASSPHRASE":git_repo.gnupg_keypair.passphrase},)Environment VariablesVariableDefault ValueDescriptionPGITF_DEBUGAdds additional debug logging.DevelopmentSource Control