From fd2227b5482a080a0c74c1b4cb4e7aaec7914dbb Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Mon, 25 Jan 2021 22:18:47 -0800 Subject: [PATCH] Fix git plugin tests. Add fake author info to environment while running the tests to avoid failure of the git commit commands. --- .github/workflows/tests.yaml | 7 +++++++ tests/test_git.py | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index fbad0e9..fb2b8e0 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -20,6 +20,13 @@ jobs: run: | python -m pip install --upgrade pip pip install -r dev_requirements.txt + - name: Configure git author (fix issue with environment variable) + run: | + # Manually sets some git user and email to avoid failure of the test + # (For some reason the environment variables set in the test are not + # taken into account by git on the runner.) + git config --global user.name "Pubs test" + git config --global user.email "unittest@pubs.org" - name: Test with pytest (mock API mode) env: PUBS_TESTS_MODE: MOCK diff --git a/tests/test_git.py b/tests/test_git.py index 192c042..d9926ba 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -1,5 +1,6 @@ -import unittest +import os import subprocess +import unittest import sand_env @@ -16,12 +17,22 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase): def setUp(self, nsec_stat=True): super(TestGitPlugin, self).setUp() + # Backup environment variables and set git author + self.env_backup = os.environ.copy() + os.environ['GIT_AUTHOR_NAME'] = "Pubs test" + os.environ['GIT_AUTHOR_EMAIL'] = "unittest@pubs.org" + # Setup pubs repository self.execute_cmds([('pubs init',)]) conf = config.load_conf(path=self.default_conf_path) conf['plugins']['active'] = ['git'] config.save_conf(conf, path=self.default_conf_path) + def tearDown(self): + super().tearDown() + os.environ = self.env_backup + def test_git(self): + print(self.default_pubs_dir) self.execute_cmds([('pubs add data/pagerank.bib',)]) hash_a = git_hash(self.default_pubs_dir) @@ -72,6 +83,7 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase): # self.assertEqual(hash_i, hash_j) def test_manual(self): + print(self.default_pubs_dir) conf = config.load_conf(path=self.default_conf_path) conf['plugins']['active'] = ['git'] conf['plugins']['git']['manual'] = True