Repository: mwouts/jupytext (language: python)

Issue:
1.11.3: pytest is failing
Just normal build, install and test cycle used on building package from non-root account:
- "setup.py build"
- "setup.py install --root </install/prefix>"
- "pytest with PYTHONPATH pointing to setearch and sitelib inside </install/prefix>
```console
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-jupytext-1.11.3-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-jupytext-1.11.3-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.11, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, expect-1.1.0, httpbin-1.0.0, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, freezegun-0.4.2, case-1.5.3, isort-1.3.0, aspectlib-1.5.2, asyncio-0.15.1, toolbox-0.5, xprocess-0.17.1, aiohttp-0.3.0, checkdocs-2.7.0, mock-3.6.1, rerunfailures-9.1.1, requests-mock-1.9.3, cov-2.12.1, pyfakefs-4.5.0, flaky-3.7.0, hypothesis-6.14.0, benchmark-3.4.1, xdist-2.3.0, pylama-7.7.1, datadir-1.3.1, regressions-2.2.0, cases-3.6.3, Faker-8.10.0
collected 2579 items

. .                                                                                                                                                                  [  0%]
tests/test_active_cells.py ............................                                                                                                              [  1%]
tests/test_auto_ext.py .............................................................x.s.......................                                                       [  4%]
tests/test_black.py ...s........                                                                                                                                     [  4%]
tests/test_cell_id.py .                                                                                                                                              [  5%]
tests/test_cell_metadata.py ............................................................                                                                             [  7%]
tests/test_cells.py ...............                                                                                                                                  [  7%]
tests/test_changelog.py ...                                                                                                                                          [  8%]
tests/test_cli.py .................................................................................................................................................. [ 13%]
.................................................................................................................................................................... [ 20%]
F........................................................................................s................                                                           [ 24%]
tests/test_cli_config.py ...........                                                                                                                                 [ 24%]
tests/test_cm_config.py ............                                                                                                                                 [ 25%]
tests/test_combine.py ..................................................                                                                                             [ 27%]
tests/test_compare.py .....................                                                                                                                          [ 27%]
tests/test_config.py .................                                                                                                                               [ 28%]
tests/test_contentsmanager.py ...................................................................................................................................... [ 33%]
.................................................................................................................................................................... [ 40%]
................................................................................................................................F................................... [ 46%]
..ss                                                                                                                                                                 [ 46%]
tests/test_custom_cell_magics.py .                                                                                                                                   [ 46%]
tests/test_doxygen.py ..........                                                                                                                                     [ 46%]
tests/test_escape_magics.py ...............................................................................                                                          [ 50%]
tests/test_execute.py ......s.                                                                                                                                       [ 50%]
tests/test_formats.py .........................                                                                                                                      [ 51%]
tests/test_header.py ..........                                                                                                                                      [ 51%]
tests/test_hide_remove_input_outputs_rmarkdown.py ........                                                                                                           [ 52%]
tests/test_ipynb_to_R.py ....                                                                                                                                        [ 52%]
tests/test_ipynb_to_myst.py .......ss...                                                                                                                             [ 52%]
tests/test_ipynb_to_py.py ....................                                                                                                                       [ 53%]
tests/test_ipynb_to_rmd.py ........................                                                                                                                  [ 54%]
tests/test_isort.py .                                                                                                                                                [ 54%]
tests/test_jupytext_errors.py ..                                                                                                                                     [ 54%]
tests/test_jupytext_nbconvert_round_trip.py .......................                                                                                                  [ 55%]
tests/test_jupytext_read.py ..                                                                                                                                       [ 55%]
tests/test_knitr_spin.py .                                                                                                                                           [ 55%]
tests/test_load_multiple.py ..                                                                                                                                       [ 55%]
tests/test_markdown_in_code_cells.py ....                                                                                                                            [ 55%]
tests/test_metadata_filter.py .................                                                                                                                      [ 56%]
tests/test_metadata_filters_from_config.py .                                                                                                                         [ 56%]
tests/test_mirror.py ............................................................................................................................................... [ 61%]
..................................................................................F................................................................................. [ 68%]
....F...................................................................................................                                                             [ 72%]
tests/test_nbformat_version.py .......                                                                                                                               [ 72%]
tests/test_paired_paths.py ...................                                                                                                                       [ 73%]
tests/test_pep8.py ...................................................................................................................                               [ 77%]
tests/test_pre_commit_0_ipynb_to_py.py E                                                                                                                             [ 77%]
tests/test_pre_commit_1_sync.py E                                                                                                                                    [ 77%]
tests/test_pre_commit_2_sync_nbstripout.py E                                                                                                                         [ 77%]
tests/test_pre_commit_3_sync_black_nbstripout.py E                                                                                                                   [ 77%]
tests/test_pre_commit_4_sync_execute.py s                                                                                                                            [ 78%]
tests/test_pre_commit_5_reformat_markdown.py E                                                                                                                       [ 78%]
tests/test_pre_commit_mode.py ............                                                                                                                           [ 78%]
tests/test_pre_commit_scripts.py ........                                                                                                                            [ 78%]
tests/test_preserve_empty_cells.py .......                                                                                                                           [ 79%]
tests/test_pytest.py ..                                                                                                                                              [ 79%]
tests/test_read_all_py.py ..........................................................................................................                                 [ 83%]
tests/test_read_dotnet_try_markdown.py ...                                                                                                                           [ 83%]
tests/test_read_folding_markers.py .....                                                                                                                             [ 83%]
tests/test_read_incomplete_rmd.py ...                                                                                                                                [ 83%]
tests/test_read_simple_R.py ............                                                                                                                             [ 84%]
tests/test_read_simple_clojure.py .                                                                                                                                  [ 84%]
tests/test_read_simple_csharp.py .......                                                                                                                             [ 84%]
tests/test_read_simple_groovy.py .                                                                                                                                   [ 84%]
tests/test_read_simple_hydrogen.py .......                                                                                                                           [ 84%]
tests/test_read_simple_ipynb.py .                                                                                                                                    [ 84%]
tests/test_read_simple_java.py .                                                                                                                                     [ 84%]
tests/test_read_simple_julia.py .                                                                                                                                    [ 84%]
tests/test_read_simple_markdown.py ....................................                                                                                              [ 86%]
tests/test_read_simple_matlab.py ..                                                                                                                                  [ 86%]
tests/test_read_simple_nomarker.py ..                                                                                                                                [ 86%]
tests/test_read_simple_pandoc.py ....s                                                                                                                               [ 86%]
tests/test_read_simple_percent.py .....................                                                                                                              [ 87%]
tests/test_read_simple_python.py ................................................                                                                                    [ 89%]
tests/test_read_simple_rmd.py .........                                                                                                                              [ 89%]
tests/test_read_simple_rust.py ...                                                                                                                                   [ 89%]
tests/test_read_simple_scheme.py .                                                                                                                                   [ 89%]
tests/test_read_simple_sphinx.py ...                                                                                                                                 [ 89%]
tests/test_read_write_functions.py .....                                                                                                                             [ 90%]
tests/test_rmd_to_ipynb.py ......                                                                                                                                    [ 90%]
tests/test_save_multiple.py .....................................................                                                                                    [ 92%]
tests/test_stringparser.py ....                                                                                                                                      [ 92%]
tests/test_trust_notebook.py ................................................                                                                                        [ 94%]
tests/test_unicode.py ...............................                                                                                                                [ 95%]
tests/test_using_cli.py .                                                                                                                                            [ 95%]
tests/test_write_does_not_modify_notebook.py ..............................................................................................................          [100%]

================================================================================== ERRORS ==================================================================================
____________________________________________________________ ERROR at setup of test_pre_commit_hook_ipynb_to_py ____________________________________________________________

jupytext_repo_root = '/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3'

    @pytest.fixture
    def jupytext_repo_rev(jupytext_repo_root):
        """The local revision of this repo, to use in .pre-commit-config.yaml in tests"""
>       return system("git", "rev-parse", "HEAD", cwd=jupytext_repo_root).strip()

/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3/tests/conftest.py:50:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = ('git', 'rev-parse', 'HEAD'), kwargs = {'cwd': '/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3', 'stdout': -1}, proc = <subprocess.Popen object at 0x7fb217414d60>
out = b'', _ = None

    def system(*args, **kwargs):
        """Execute the given bash command"""
        kwargs.setdefault("stdout", subprocess.PIPE)
        proc = subprocess.Popen(args, **kwargs)
        out, _ = proc.communicate()
        if proc.returncode:
>           raise SystemExit(proc.returncode)
E           SystemExit: 128

/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3/jupytext/cli.py:50: SystemExit
-------------------------------------------------------------------------- Captured stderr setup ---------------------------------------------------------------------------
fatal: not a git repository (or any parent up to mount point /home/tkloczko)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
_______________________________________________________________ ERROR at setup of test_pre_commit_hook_sync ________________________________________________________________

jupytext_repo_root = '/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3'

    @pytest.fixture
    def jupytext_repo_rev(jupytext_repo_root):
        """The local revision of this repo, to use in .pre-commit-config.yaml in tests"""
>       return system("git", "rev-parse", "HEAD", cwd=jupytext_repo_root).strip()

/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3/tests/conftest.py:50:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = ('git', 'rev-parse', 'HEAD'), kwargs = {'cwd': '/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3', 'stdout': -1}, proc = <subprocess.Popen object at 0x7fb21741c3a0>
out = b'', _ = None

    def system(*args, **kwargs):
        """Execute the given bash command"""
        kwargs.setdefault("stdout", subprocess.PIPE)
        proc = subprocess.Popen(args, **kwargs)
        out, _ = proc.communicate()
        if proc.returncode:
>           raise SystemExit(proc.returncode)
E           SystemExit: 128

/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3/jupytext/cli.py:50: SystemExit
-------------------------------------------------------------------------- Captured stderr setup ---------------------------------------------------------------------------
fatal: not a git repository (or any parent up to mount point /home/tkloczko)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
__________________________________________________________ ERROR at setup of test_pre_commit_hook_sync_nbstripout __________________________________________________________

jupytext_repo_root = '/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3'

    @pytest.fixture
    def jupytext_repo_rev(jupytext_repo_root):
        """The local revision of this repo, to use in .pre-commit-config.yaml in tests"""
>       return system("git", "rev-parse", "HEAD", cwd=jupytext_repo_root).strip()

/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3/tests/conftest.py:50:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = ('git', 'rev-parse', 'HEAD'), kwargs = {'cwd': '/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3', 'stdout': -1}, proc = <subprocess.Popen object at 0x7fb217447670>
out = b'', _ = None

    def system(*args, **kwargs):
        """Execute the given bash command"""
        kwargs.setdefault("stdout", subprocess.PIPE)
        proc = subprocess.Popen(args, **kwargs)
        out, _ = proc.communicate()
        if proc.returncode:
>           raise SystemExit(proc.returncode)
E           SystemExit: 128

/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3/jupytext/cli.py:50: SystemExit
-------------------------------------------------------------------------- Captured stderr setup ---------------------------------------------------------------------------
fatal: not a git repository (or any parent up to mount point /home/tkloczko)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
_______________________________________________________ ERROR at setup of test_pre_commit_hook_sync_black_nbstripout _______________________________________________________
```



Discussion / hints:
Hi @kloczek , thanks for reporting this. Indeed some of the tests (eg the ones on the pre-commit hook) assume that the jupytext directory is a git folder.

That assumption does not seem to hold in your case.

Could you please tell us a bit more about your use case, and how I can reproduce? Thanks !

Fix patch:
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index d3a336593..4cc25f557 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -7,6 +7,9 @@ Jupytext ChangeLog
 **Changed**
 - (Documentation) the `cell_markers` option (and the other ones) can be set directly in the `jupytext.toml` config file ([#809](https://github.com/mwouts/jupytext/issues/809)).
 
+**Fixed**
+- The pre-commit tests are skipped when the Jupytext folder is not a git repository ([#814](https://github.com/mwouts/jupytext/issues/814))
+
 
 1.11.3 (2021-06-10)
 -------------------


Test patch:
diff --git a/tests/test_pre_commit_0_ipynb_to_py.py b/tests/test_pre_commit_0_ipynb_to_py.py
index 5bd6e2209..87c284160 100644
--- a/tests/test_pre_commit_0_ipynb_to_py.py
+++ b/tests/test_pre_commit_0_ipynb_to_py.py
@@ -7,10 +7,14 @@
 from jupytext.cli import jupytext
 from jupytext.compare import compare_cells
 
-from .utils import skip_pre_commit_tests_on_windows
+from .utils import (
+    skip_pre_commit_tests_on_windows,
+    skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo,
+)
 
 
 @skip_pre_commit_tests_on_windows
+@skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo
 def test_pre_commit_hook_ipynb_to_py(
     tmpdir, cwd_tmpdir, tmp_repo, jupytext_repo_root, jupytext_repo_rev
 ):
diff --git a/tests/test_pre_commit_1_sync.py b/tests/test_pre_commit_1_sync.py
index bfad5ada7..256e72fcd 100644
--- a/tests/test_pre_commit_1_sync.py
+++ b/tests/test_pre_commit_1_sync.py
@@ -8,10 +8,14 @@
 from jupytext import read, write
 from jupytext.cli import jupytext
 
-from .utils import skip_pre_commit_tests_on_windows
+from .utils import (
+    skip_pre_commit_tests_on_windows,
+    skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo,
+)
 
 
 @skip_pre_commit_tests_on_windows
+@skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo
 def test_pre_commit_hook_sync(
     tmpdir,
     cwd_tmpdir,
diff --git a/tests/test_pre_commit_2_sync_nbstripout.py b/tests/test_pre_commit_2_sync_nbstripout.py
index baa2f896e..afb55a976 100644
--- a/tests/test_pre_commit_2_sync_nbstripout.py
+++ b/tests/test_pre_commit_2_sync_nbstripout.py
@@ -5,10 +5,14 @@
 from jupytext import read, write
 from jupytext.cli import jupytext
 
-from .utils import skip_pre_commit_tests_on_windows
+from .utils import (
+    skip_pre_commit_tests_on_windows,
+    skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo,
+)
 
 
 @skip_pre_commit_tests_on_windows
+@skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo
 def test_pre_commit_hook_sync_nbstripout(
     tmpdir,
     cwd_tmpdir,
diff --git a/tests/test_pre_commit_3_sync_black_nbstripout.py b/tests/test_pre_commit_3_sync_black_nbstripout.py
index 3ab8b3b66..9fbc6aabe 100644
--- a/tests/test_pre_commit_3_sync_black_nbstripout.py
+++ b/tests/test_pre_commit_3_sync_black_nbstripout.py
@@ -4,10 +4,14 @@
 
 from jupytext import read, write
 
-from .utils import skip_pre_commit_tests_on_windows
+from .utils import (
+    skip_pre_commit_tests_on_windows,
+    skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo,
+)
 
 
 @skip_pre_commit_tests_on_windows
+@skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo
 def test_pre_commit_hook_sync_black_nbstripout(
     tmpdir,
     cwd_tmpdir,
diff --git a/tests/test_pre_commit_4_sync_execute.py b/tests/test_pre_commit_4_sync_execute.py
index 3b2b22b77..7b64516f7 100644
--- a/tests/test_pre_commit_4_sync_execute.py
+++ b/tests/test_pre_commit_4_sync_execute.py
@@ -5,11 +5,16 @@
 
 from jupytext import read, write
 
-from .utils import requires_user_kernel_python3, skip_pre_commit_tests_on_windows
+from .utils import (
+    requires_user_kernel_python3,
+    skip_pre_commit_tests_on_windows,
+    skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo,
+)
 
 
 @requires_user_kernel_python3
 @skip_pre_commit_tests_on_windows
+@skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo
 def test_pre_commit_hook_sync_execute(
     tmpdir,
     cwd_tmpdir,
diff --git a/tests/test_pre_commit_5_reformat_markdown.py b/tests/test_pre_commit_5_reformat_markdown.py
index 0344ac19b..f542b19cf 100644
--- a/tests/test_pre_commit_5_reformat_markdown.py
+++ b/tests/test_pre_commit_5_reformat_markdown.py
@@ -5,11 +5,16 @@
 
 from jupytext import read, write
 
-from .utils import requires_pandoc, skip_pre_commit_tests_on_windows
+from .utils import (
+    requires_pandoc,
+    skip_pre_commit_tests_on_windows,
+    skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo,
+)
 
 
 @requires_pandoc
 @skip_pre_commit_tests_on_windows
+@skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo
 def test_pre_commit_hook_sync_reformat_code_and_markdown(
     tmpdir,
     cwd_tmpdir,
diff --git a/tests/utils.py b/tests/utils.py
index b2c294a80..447aa0719 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -2,6 +2,7 @@
 import os
 import re
 import sys
+from pathlib import Path
 
 import pytest
 from jupyter_client.kernelspec import find_kernel_specs, get_kernel_spec
@@ -74,6 +75,10 @@ def isort_version():
     sys.platform.startswith("win"),
     reason="OSError: [WinError 193] %1 is not a valid Win32 application",
 )
+skip_pre_commit_tests_when_jupytext_folder_is_not_a_git_repo = pytest.mark.skipif(
+    not (Path(__file__).parent.parent / ".git").is_dir(),
+    reason="Jupytext folder is not a git repository #814",
+)
 
 
 def list_notebooks(path="ipynb", skip="World"):