Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.1.0: pytest fails in two units #80

Open
kloczek opened this issue Mar 31, 2024 · 2 comments
Open

3.1.0: pytest fails in two units #80

kloczek opened this issue Mar 31, 2024 · 2 comments
Labels
tests Add or improve existing tests

Comments

@kloczek
Copy link

kloczek commented Mar 31, 2024

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

  • python3 -sBm build -w --no-isolation
  • because I'm calling build with --no-isolation I'm using during all processes only locally installed modules
  • install .whl file in </install/prefix> using installer module
  • run pytest with $PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>
  • build is performed in env which is cut off from access to the public network (pytest is executed with -m "not network")
Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-versioningit-3.1.0-2.fc36.x86_64/usr/lib64/python3.9/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-versioningit-3.1.0-2.fc36.x86_64/usr/lib/python3.9/site-packages
+ /usr/bin/pytest -ra -m 'not network'
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.9.18, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/tkloczko/rpmbuild/BUILD/versioningit-3.1.0
configfile: tox.ini
plugins: mock-3.14.0
collected 534 items

test/test_config.py ....................                                                                                                                                              [  3%]
test/test_end2end.py .............s.................................sssssssss...........F........F..                                                                                  [ 18%]
test/test_get_version.py ..                                                                                                                                                           [ 18%]
test/test_logging.py ...........................................                                                                                                                      [ 26%]
test/test_main.py ..........................                                                                                                                                          [ 31%]
test/test_methods/test_format.py .........                                                                                                                                            [ 33%]
test/test_methods/test_git.py ............................s                                                                                                                           [ 38%]
test/test_methods/test_hg.py sssssss.sssssss......                                                                                                                                    [ 42%]
test/test_methods/test_next_version.py .....................................................................................................                                          [ 61%]
test/test_methods/test_onbuild.py .......................................                                                                                                             [ 69%]
test/test_methods/test_tag2version.py .............                                                                                                                                   [ 71%]
test/test_methods/test_template_fields.py ................                                                                                                                            [ 74%]
test/test_methods/test_write.py ........                                                                                                                                              [ 76%]
test/test_util.py ...........................................s....................................................................................                                    [100%]

========================================================================================= FAILURES ==========================================================================================
___________________________________________________________________________ test_end2end_error[errors/hg-no-tag] ____________________________________________________________________________

tmp_path = PosixPath('/tmp/pytest-of-tkloczko/pytest-228/test_end2end_error_errors_hg_n0')
repozip = PosixPath('/home/tkloczko/rpmbuild/BUILD/versioningit-3.1.0/test/data/repos/errors/hg-no-tag.zip')
details = ErrorDetails(type='NoTagError', message="No latest tag in Mercurial repository (pattern = 're:^v')")

    @pytest.mark.parametrize(
        "repozip,details", mkcases("errors", [needs_git], details_cls=ErrorDetails)
    )
    def test_end2end_error(tmp_path: Path, repozip: Path, details: ErrorDetails) -> None:
        shutil.unpack_archive(repozip, tmp_path)
        with pytest.raises(Error) as excinfo:
            get_version(project_dir=tmp_path, write=False, fallback=True)
>       assert type(excinfo.value).__name__ == details.type
E       AssertionError: assert 'NotSdistError' == 'NoTagError'
E
E         - NoTagError
E         + NotSdistError

test/test_end2end.py:249: AssertionError
------------------------------------------------------------------------------------- Captured log call -------------------------------------------------------------------------------------
DEBUG    versioningit:methods.py:60 Loading entry point 'hg' in group versioningit.vcs
DEBUG    versioningit:methods.py:60 Loading entry point 'basic' in group versioningit.tag2version
DEBUG    versioningit:methods.py:60 Loading entry point 'minor' in group versioningit.next_version
DEBUG    versioningit:methods.py:60 Loading entry point 'basic' in group versioningit.format
DEBUG    versioningit:methods.py:60 Loading entry point 'basic' in group versioningit.template_fields
DEBUG    versioningit:util.py:64 Running: hg --cwd /tmp/pytest-of-tkloczko/pytest-228/test_end2end_error_errors_hg_n0 files .
INFO     versioningit:core.py:280 Could not get VCS data from /tmp/pytest-of-tkloczko/pytest-228/test_end2end_error_errors_hg_n0: hg not installed; assuming this isn't a Mercurial repository
INFO     versioningit:core.py:281 Falling back to reading from PKG-INFO
_________________________________________________________________________________ test_editable_mode[cmd1] __________________________________________________________________________________

cmd = ['setup.py', 'develop'], tmp_path = PosixPath('/tmp/pytest-of-tkloczko/pytest-228/test_editable_mode_cmd1_0')

    @needs_git
    @pytest.mark.parametrize(
        "cmd",
        [
            ["-m", "pip", "install", "--no-build-isolation", "-e", "."],
            ["setup.py", "develop"],
        ],
    )
    def test_editable_mode(cmd: list[str], tmp_path: Path) -> None:
        repozip = DATA_DIR / "repos" / "git" / "onbuild-write.zip"
        details = CaseDetails.model_validate_json(
            repozip.with_suffix(".json").read_text(encoding="utf-8")
        )
        srcdir = tmp_path / "src"
        shutil.unpack_archive(repozip, srcdir)
        status = get_repo_status(srcdir)
>       subprocess.run([sys.executable, *cmd], cwd=str(srcdir), check=True)

test/test_end2end.py:374:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

input = None, capture_output = False, timeout = None, check = True, popenargs = (['/usr/bin/python3', 'setup.py', 'develop'],)
kwargs = {'cwd': '/tmp/pytest-of-tkloczko/pytest-228/test_editable_mode_cmd1_0/src'}, process = <Popen: returncode: 1 args: ['/usr/bin/python3', 'setup.py', 'develop']>, stdout = None
stderr = None, retcode = 1

    def run(*popenargs,
            input=None, capture_output=False, timeout=None, check=False, **kwargs):
        """Run command with arguments and return a CompletedProcess instance.

        The returned instance will have attributes args, returncode, stdout and
        stderr. By default, stdout and stderr are not captured, and those attributes
        will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.

        If check is True and the exit code was non-zero, it raises a
        CalledProcessError. The CalledProcessError object will have the return code
        in the returncode attribute, and output & stderr attributes if those streams
        were captured.

        If timeout is given, and the process takes too long, a TimeoutExpired
        exception will be raised.

        There is an optional argument "input", allowing you to
        pass bytes or a string to the subprocess's stdin.  If you use this argument
        you may not also use the Popen constructor's "stdin" argument, as
        it will be used internally.

        By default, all communication is in bytes, and therefore any "input" should
        be bytes, and the stdout and stderr will be bytes. If in text mode, any
        "input" should be a string, and stdout and stderr will be strings decoded
        according to locale encoding, or by "encoding" if set. Text mode is
        triggered by setting any of text, encoding, errors or universal_newlines.

        The other arguments are the same as for the Popen constructor.
        """
        if input is not None:
            if kwargs.get('stdin') is not None:
                raise ValueError('stdin and input arguments may not both be used.')
            kwargs['stdin'] = PIPE

        if capture_output:
            if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
                raise ValueError('stdout and stderr arguments may not be used '
                                 'with capture_output.')
            kwargs['stdout'] = PIPE
            kwargs['stderr'] = PIPE

        with Popen(*popenargs, **kwargs) as process:
            try:
                stdout, stderr = process.communicate(input, timeout=timeout)
            except TimeoutExpired as exc:
                process.kill()
                if _mswindows:
                    # Windows accumulates the output in a single blocking
                    # read() call run on child threads, with the timeout
                    # being done in a join() on those threads.  communicate()
                    # _after_ kill() is required to collect that and add it
                    # to the exception.
                    exc.stdout, exc.stderr = process.communicate()
                else:
                    # POSIX _communicate already populated the output so
                    # far into the TimeoutExpired exception.
                    process.wait()
                raise
            except:  # Including KeyboardInterrupt, communicate handled that.
                process.kill()
                # We don't call process.wait() as .__exit__ does that for us.
                raise
            retcode = process.poll()
            if check and retcode:
>               raise CalledProcessError(retcode, process.args,
                                         output=stdout, stderr=stderr)
E               subprocess.CalledProcessError: Command '['/usr/bin/python3', 'setup.py', 'develop']' returned non-zero exit status 1.

/usr/lib64/python3.9/subprocess.py:528: CalledProcessError
----------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------
running develop
----------------------------------------------------------------------------------- Captured stderr call ------------------------------------------------------------------------------------
/usr/lib/python3.9/site-packages/setuptools/command/develop.py:40: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
/usr/lib/python3.9/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` directly.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
        ********************************************************************************

!!
  self.initialize_options()
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 13] Permission denied: '/usr/lib/python3.9/site-packages/test-easy-install-3661377.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/lib/python3.9/site-packages/

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

  https://setuptools.pypa.io/en/latest/deprecated/easy_install.html

Please make the appropriate changes for your system and try again.

------------------------------------------------------------------------------------- Captured log call -------------------------------------------------------------------------------------
DEBUG    versioningit:util.py:64 Running: git status --porcelain
================================================================================== short test summary info ==================================================================================
SKIPPED [1] test/test_end2end.py:96: Only run when --oldsetup is given
SKIPPED [9] test/test_end2end.py:96: Mercurial not installed
SKIPPED [1] test/test_methods/test_git.py:309: Git must not be installed
SKIPPED [6] test/test_methods/test_hg.py:34: Mercurial not installed
SKIPPED [1] test/test_methods/test_hg.py:70: Mercurial not installed
SKIPPED [1] test/test_methods/test_hg.py:84: Mercurial not installed
SKIPPED [2] test/test_methods/test_hg.py:91: Mercurial not installed
SKIPPED [1] test/test_methods/test_hg.py:100: Mercurial not installed
SKIPPED [1] test/test_methods/test_hg.py:110: Mercurial not installed
SKIPPED [1] test/test_methods/test_hg.py:139: Mercurial not installed
SKIPPED [1] test/test_methods/test_hg.py:149: Mercurial not installed
SKIPPED [1] test/test_util.py:146: Windows only
FAILED test/test_end2end.py::test_end2end_error[errors/hg-no-tag] - AssertionError: assert 'NotSdistError' == 'NoTagError'
FAILED test/test_end2end.py::test_editable_mode[cmd1] - subprocess.CalledProcessError: Command '['/usr/bin/python3', 'setup.py', 'develop']' returned non-zero exit status 1.
=================================================================== 2 failed, 506 passed, 26 skipped in 84.23s (0:01:24) ====================================================================
List of installed modules in build env:
Package                       Version
----------------------------- -----------
alabaster                     0.7.16
annotated-types               0.6.0
Babel                         2.14.0
build                         1.1.1
charset-normalizer            3.3.2
docutils                      0.20.1
editables                     0.5
exceptiongroup                1.1.3
hatchling                     1.21.1
idna                          3.6
imagesize                     1.4.1
importlib_metadata            7.1.0
iniconfig                     2.0.0
installer                     0.7.0
Jinja2                        3.1.3
MarkupSafe                    2.1.5
packaging                     24.0
pathspec                      0.12.1
pluggy                        1.4.0
pydantic                      2.6.4
pydantic_core                 2.16.3
Pygments                      2.17.2
pyproject_hooks               1.0.0
pytest                        8.1.1
pytest-mock                   3.14.0
python-dateutil               2.9.0.post0
requests                      2.31.0
setuptools                    69.1.1
snowballstemmer               2.2.0
Sphinx                        7.2.6
sphinx-copybutton             0.5.2
sphinx_inline_tabs            2023.4.21
sphinxcontrib-applehelp       1.0.8
sphinxcontrib-devhelp         1.0.5
sphinxcontrib-htmlhelp        2.0.5
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.7
sphinxcontrib-serializinghtml 1.1.10
tokenize_rt                   5.2.0
tomli                         2.0.1
trove-classifiers             2024.3.25
typing_extensions             4.10.0
urllib3                       1.26.18
wheel                         0.43.0
zipp                          3.18.1

Please let me know if you need more details or want me to perform some diagnostics.

@jwodder
Copy link
Owner

jwodder commented Apr 9, 2024

  • The test_end2end_error[errors/hg-no-tag] test is failing because it requires Mercurial to be installed, but the test isn't correctly marked as requiring Mercurial (If it had been marked correctly, the test would have been skippped). I'll fix this in a bit.

  • The test_editable_mode[cmd1] test is failing because the test tries to run setup.py develop on a test project, and setuptools on your machine then tries to install the test project in /usr/lib/python3.9/site-packages/, which it doesn't have write access to. This test (and several others) is intended to be run in a virtual environment in order to avoid permission issues like this.

@jwodder jwodder added the tests Add or improve existing tests label Apr 9, 2024
@jwodder
Copy link
Owner

jwodder commented Apr 29, 2024

I have just released versioningit v3.1.1, containing a fix for the test_end2end_error[errors/hg-no-tag] issue. Are you still having problems with the test_editable_mode[cmd1] test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Add or improve existing tests
Projects
None yet
Development

No branches or pull requests

2 participants