Files
pipenv/tests/integration/test_run.py
T
Matt Davis 9848862927 Convert test runner to use pypiserver package as standalone process (#5284)
* Check point progress on moving tests to pypiserver.

* Allow other indexes to mimic the pypi json API for package hashes.

* Fix these tests that run on lower python versions only.

* Try adding the pypiserver to the github actions to only run once.

* Expand the scope of fixtures for pypiserver.

* try to accomedate microsoft runner.

* Windows networking troubles.

* Remove running as a background job.

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to introduce pypi as the root index because setuptools-scm is not in our pypi artifacts.

* see if the windows tests run faster (and the other tests) by supplying waitress.

* Only use waitress on windows because the others are fast on the default.  Fix requests pollution.

* Supply a suitable Pipfile instead for these two failing tests.

* More requests resolver cross test contamination cleanup.

* remove problematic tests because even on my version of python 3.8.12 this does not work due to AttributeError: 'HTMLParser' object has no attribute 'unescape'

* fix mirror install test.

* Fix Pipfile.

* Fix Pipfile for real

* Fix tests

* Cleanup test naming and more test enhancements.

* Save this optimization for a subsequent PR.

* Cleanup the TemporaryDirectory between tests.

* resolve merge conflict.

* Cleanup path initalization -- it hsould always be a TemporaryDirectory for tests that gets cleanedup.

* Cleanup path initalization -- it hsould always be a TemporaryDirectory for tests that gets cleanedup.

* tableflip on those requests tests that read the setup metadata in reqlib from other tests.

* Update developer documentation for running tests.

* add news fragment.

* Try gunicorn perfoormance for linux/mac

* Only use gunicorn on linux based on the results of last run.
2022-09-05 10:19:12 -04:00

130 lines
4.1 KiB
Python

import os
import pytest
from pipenv.project import Project
from pipenv.utils.shell import subprocess_run, temp_environ
@pytest.mark.run
@pytest.mark.dotenv
def test_env(pipenv_instance_pypi):
with pipenv_instance_pypi(pipfile=False, chdir=True) as p:
with open(os.path.join(p.path, ".env"), "w") as f:
f.write("HELLO=WORLD")
c = subprocess_run(['pipenv', 'run', 'python', '-c', "import os; print(os.environ['HELLO'])"], env=p.env)
assert c.returncode == 0
assert 'WORLD' in c.stdout
@pytest.mark.run
def test_scripts(pipenv_instance_pypi):
with pipenv_instance_pypi(chdir=True) as p:
with open(p.pipfile_path, 'w') as f:
f.write(r"""
[scripts]
printfoo = "python -c \"print('foo')\""
notfoundscript = "randomthingtotally"
appendscript = "cmd arg1"
multicommand = "bash -c \"cd docs && make html\""
""")
if os.name == "nt":
f.write('scriptwithenv = "echo %HELLO%"\n')
else:
f.write('scriptwithenv = "echo $HELLO"\n')
c = p.pipenv('install')
assert c.returncode == 0
c = p.pipenv('run printfoo')
assert c.returncode == 0
assert c.stdout.strip() == 'foo'
assert not c.stderr.strip()
c = p.pipenv('run notfoundscript')
assert c.returncode != 0
assert c.stdout == ''
if os.name != 'nt': # TODO: Implement this message for Windows.
assert 'not found' in c.stderr
project = Project()
script = project.build_script('multicommand')
assert script.command == 'bash'
assert script.args == ['-c', 'cd docs && make html']
script = project.build_script('appendscript', ['a', 'b'])
assert script.command == 'cmd'
assert script.args == ['arg1', 'a', 'b']
with temp_environ():
os.environ['HELLO'] = 'WORLD'
c = p.pipenv("run scriptwithenv")
assert c.returncode == 0
if os.name != "nt": # This doesn't work on CI windows.
assert c.stdout.strip() == "WORLD"
@pytest.mark.run
@pytest.mark.skip_windows
def test_run_with_usr_env_shebang(pipenv_instance_pypi):
with pipenv_instance_pypi(chdir=True) as p:
p.pipenv('install')
script_path = os.path.join(p.path, "test_script")
with open(script_path, "w") as f:
f.write(
"#!/usr/bin/env python\n"
"import sys, os\n\n"
"print(sys.prefix)\n"
"print(os.getenv('VIRTUAL_ENV'))\n"
)
os.chmod(script_path, 0o700)
c = p.pipenv("run ./test_script")
assert c.returncode == 0
project = Project()
lines = [line.strip() for line in c.stdout.splitlines()]
assert all(line == project.virtualenv_location for line in lines)
@pytest.mark.run
@pytest.mark.parametrize('quiet', [True, False])
def test_scripts_resolve_dot_env_vars(quiet, pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
with open(".env", "w") as f:
contents = """
HELLO_VAR=WORLD
""".strip()
f.write(contents)
with open(p.pipfile_path, "w") as f:
contents = """
[scripts]
hello = "echo $HELLO_VAR"
""".strip()
f.write(contents)
if quiet:
c = p.pipenv('run --quiet hello')
else:
c = p.pipenv('run hello')
assert c.returncode == 0
assert 'WORLD\n' == c.stdout
@pytest.mark.run
@pytest.mark.parametrize('quiet', [True, False])
def test_pipenv_run_pip_freeze_has_expected_output(quiet, pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[packages]
requests = "==2.14.0"
""".strip()
f.write(contents)
c = p.pipenv('install')
assert c.returncode == 0
if quiet:
c = p.pipenv('run --quiet pip freeze')
else:
c = p.pipenv('run pip freeze')
assert c.returncode == 0
assert 'requests==2.14.0\n' == c.stdout