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

Running tests on a system-wide install. #1235

Closed
Aniket-Pradhan opened this issue Dec 6, 2019 · 6 comments
Closed

Running tests on a system-wide install. #1235

Aniket-Pradhan opened this issue Dec 6, 2019 · 6 comments
Labels

Comments

@Aniket-Pradhan
Copy link

@Aniket-Pradhan Aniket-Pradhan commented Dec 6, 2019

Hello there!

Thanks for providing such an amazing tool. It is really helpful and simply eases out the development pipeline.

I/We were packaging pre-commit for Fedora (a Linux distribution) and were stuck in running the tests for the installation. I cannot find steps to run the tests for system-wide installation, but only for a virtual-environment. Currently, I am running the tests as:

$ # In the project directory, after installing the tool (python setup.py install)
$ git init # since the tests require a git repo for running (I am using the release tar)
$ export PYTHONPATH=/usr/lib/python3.7/site-packages
$ pytest-3

The installation worked out completely fine, but some of the tests fail, as described below. It would be really helpful if you could explain how can we amend running the tests.

Test failures:

tests/parse_shebang_test.py ..............FFFF
tests/languages/python_test.py ...........F
    def test_normalize_cmd_PATH():
        cmd = ('python', '--version')
        expected = (distutils.spawn.find_executable('python'), '--version')
>       assert parse_shebang.normalize_cmd(cmd) == expected
tests/parse_shebang_test.py:130: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pre_commit/parse_shebang.py:72: in normalize_cmd
    exe = normexe(cmd[0])
pre_commit/parse_shebang.py:52: in normexe
    _error('not found')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
msg = 'not found'
    def _error(msg):
>       raise ExecutableNotFoundError('Executable `{}` {}'.format(orig, msg))
E       pre_commit.parse_shebang.ExecutableNotFoundError: Executable `python` not found
pre_commit/parse_shebang.py:47: ExecutableNotFoundError
__________________________ test_normalize_cmd_shebang __________________________
in_tmpdir = '/tmp/pytest-of-mockbuild/pytest-0/test_normalize_cmd_shebang0/0'
    def test_normalize_cmd_shebang(in_tmpdir):
>       python = distutils.spawn.find_executable('python').replace(os.sep, '/')
E       AttributeError: 'NoneType' object has no attribute 'replace'
/builddir/build/BUILD/pre-commit-1.20.0/tests/parse_shebang_test.py:134: AttributeError
__________________ test_normalize_cmd_PATH_shebang_full_path ___________________
in_tmpdir = '/tmp/pytest-of-mockbuild/pytest-0/test_normalize_cmd_PATH_sheban0/0'
    def test_normalize_cmd_PATH_shebang_full_path(in_tmpdir):
>       python = distutils.spawn.find_executable('python').replace(os.sep, '/')
E       AttributeError: 'NoneType' object has no attribute 'replace'
/builddir/build/BUILD/pre-commit-1.20.0/tests/parse_shebang_test.py:140: AttributeError
_____________________ test_normalize_cmd_PATH_shebang_PATH _____________________
in_tmpdir = '/tmp/pytest-of-mockbuild/pytest-0/test_normalize_cmd_PATH_sheban1/0'
    def test_normalize_cmd_PATH_shebang_PATH(in_tmpdir):
        python = distutils.spawn.find_executable('python')
        path = write_executable('/usr/bin/env python')
        with bin_on_path():
>           ret = parse_shebang.normalize_cmd(('run',))
/builddir/build/BUILD/pre-commit-1.20.0/tests/parse_shebang_test.py:151: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/builddir/build/BUILD/pre-commit-1.20.0/pre_commit/parse_shebang.py:78: in normalize_cmd
    exe = normexe(cmd[0])
/builddir/build/BUILD/pre-commit-1.20.0/pre_commit/parse_shebang.py:52: in normexe
    _error('not found')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
msg = 'not found'
    def _error(msg):
>       raise ExecutableNotFoundError('Executable `{}` {}'.format(orig, msg))
E       pre_commit.parse_shebang.ExecutableNotFoundError: Executable `python` not found
/builddir/build/BUILD/pre-commit-1.20.0/pre_commit/parse_shebang.py:47: ExecutableNotFoundError
_________________________ test_healthy_types_py_in_cwd _________________________
tmpdir = local('/tmp/pytest-of-mockbuild/pytest-0/test_healthy_types_py_in_cwd0')
    def test_healthy_types_py_in_cwd(tmpdir):
        with tmpdir.as_cwd():
            # even if a `types.py` file exists, should still be healthy
            tmpdir.join('types.py').ensure()
            # this env doesn't actually exist (for test speed purposes)
>           assert python.healthy(Prefix(str(tmpdir)), C.DEFAULT) is True
E           AssertionError: assert False is True
E            +  where False = <function py_interface.<locals>.healthy at 0xb578d928>(Prefix(prefix_dir='/tmp/pytest-of-mockbuild/pytest-0/test_healthy_types_py_in_cwd0'), 'default')
E            +    where <function py_interface.<locals>.healthy at 0xb578d928> = python.healthy
E            +    and   Prefix(prefix_dir='/tmp/pytest-of-mockbuild/pytest-0/test_healthy_types_py_in_cwd0') = Prefix('/tmp/pytest-of-mockbuild/pytest-0/test_healthy_types_py_in_cwd0')
E            +      where '/tmp/pytest-of-mockbuild/pytest-0/test_healthy_types_py_in_cwd0' = str(local('/tmp/pytest-of-mockbuild/pytest-0/test_healthy_types_py_in_cwd0'))
E            +    and   'default' = C.DEFAULT
tests/languages/python_test.py:60: AssertionError

TL;DR: I want to run the tests for a system-wide installation. I am facing several test failiures as highlighted above.

I was also getting an error similar to #1032. I do not understand what you mean by this comment. How would you/I modify the PATH in order to run the test correctly for a system-wide (global) install?

It would be really great if you could help us with the same. :D

@asottile
Copy link
Member

@asottile asottile commented Dec 6, 2019

hmmm I think each of those tests are a matter of s/python/python3/ or some such -- let me make a patch and see if that helps you?

@asottile
Copy link
Member

@asottile asottile commented Dec 6, 2019

#1236 should make the parse_shebang tests work betterer

@asottile asottile added the question label Dec 6, 2019
@asottile
Copy link
Member

@asottile asottile commented Dec 6, 2019

should be fixed with #1237 merged as well

@asottile asottile closed this Dec 6, 2019
@Aniket-Pradhan
Copy link
Author

@Aniket-Pradhan Aniket-Pradhan commented Dec 7, 2019

hmmm I think each of those tests are a matter of s/python/python3/ or some such -- let me make a patch and see if that helps you?

Yep, you are correct about the same. I guess that's why the tests were failing on the build system (and not locally). Anyhow, the patch works, and the tests are working fine now. Thanks a lot, for helping me out here, and for a quick response too. 😄

@Aniket-Pradhan
Copy link
Author

@Aniket-Pradhan Aniket-Pradhan commented Dec 7, 2019

I was also getting an error similar to #1032. I do not understand what you mean by this comment. How should I modify the PATH in order to run the test correctly for a system-wide (global) install?

Can you also help me with this one? Should I "constrain" the PATH (or the PYTHONPATH) to include the package installation directory as well (/usr/lib/python3.7/site-packages)?

@asottile
Copy link
Member

@asottile asottile commented Dec 7, 2019

probably just skip that test -- everythng else wil be broken with /usr/bin not on PATH -- the test doesn't really make all that much sense for a system install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.