-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
tmpdir and subprocess fail in CI environment, work locally #2686
Comments
Hi @menzenski, Thanks for setting up a repository demonstrating the problem, we appreciate it. Your call to
Why do you need this call? There are better ways to change the working directory:
I'm short on time now to research the details, but on Windows |
Hi @nicoddemus , thank you for the comment. I did a poor job constructing the MWE repo — Your tip about using |
@menzenski thanks for the feedback, if possible could you describe the problem/solution a bit more in detail |
@RonnyPfannschmidt sure. I am working on a fork of https://github.com/nvie/cookiecutter-python-cli that uses pipenv to manage dependencies and virtual environments, and wanted to write a test which would:
My first attempt at a test that did these three things looked like this: import json
import os
import os.path
import subprocess
def test_cookiecuttering(tmpdir):
# read the package name from the default cookiecutter config file
root_dir = os.path.join(os.path.dirname(__file__), os.pardir)
with open(os.path.join(root_dir, 'cookiecutter.json')) as config_file:
config_data = json.load(config_file)
repo_name = config_data['repo_name']
package_name = config_data['package_name']
assert package_name and isinstance(package_name, str)
# generate the package with the cookiecutter CLI command
subprocess.check_call([
'cookiecutter', 'https://github.com/menzenski/cookiecutter-python-cli',
'--checkout', 'pipfile', '--no-input', '--overwrite-if-exists',
'--output-dir', tmpdir.strpath
])
# the directory where the generated package is located
repo_dir = tmpdir.join(repo_name)
# run the setup command in the package dir to install dependencies
subprocess.check_call(['make', '-C', repo_dir.strpath, 'setup'])
# run the test command in the package dir
subprocess.check_call(['make', '-C', repo_dir.strpath, 'test']) That passed locally but failed in Travis CI with The following test passed both locally and in Travis CI: import cookiecutter.main as cookiecutter
import json
import os
import os.path
import subprocess
def test_cookiecuttering(monkeypatch, tmpdir):
# read the package name from the default cookiecutter config file
root_dir = os.path.join(os.path.dirname(__file__), os.pardir)
with open(os.path.join(root_dir, 'cookiecutter.json')) as config_file:
config_data = json.load(config_file)
repo_name = config_data['repo_name']
package_name = config_data['package_name']
assert package_name and isinstance(package_name, str)
monkeypatch.chdir(root_dir)
# generate the package with the cookiecutter function
cookiecutter.cookiecutter(
'https://github.com/menzenski/cookiecutter-python-cli',
checkout='pipfile', no_input=True, overwrite_if_exists=True,
default_config=True)
# change working directory to the generated project's root directory
tmpdir.join(repo_name)
monkeypatch.chdir(repo_name)
# run the setup command in the package dir to install dependencies
subprocess.check_call(['make', 'setup'])
# # run the test command in the package dir
subprocess.check_call(['make', 'test']) Part of the solution here was importing and calling |
I have some tests that direct output of a directory-creating command to
tmpdir
, then invoke a command from the Makefile located in the directory which was created.These tests pass on my local machine but do not pass in my Travis CI environment.
The project uses Pipfile to manage dependencies.
My local machine is running Mac 10.11.6, with Python version 3.5.2 (from a pipenv virtual environment). The Travis CI build runs on Ubuntu Trusty 14.04 with Python 3.5.3.
Minimal Working Example
I have put together a minimal working example repo here: https://github.com/menzenski/pipenv-travis-test with a simplified test which nevertheless exhibits the same behavior: it creates a tempdir and then calls
subprocess.check_call
with the path to the tempdir as an argument. It passes on my local machine but fails (with the same error) in the Travis CI environment. The pytest version used is 3.0.7 .Output on my local machine, which passes:
Output from the travis build, which fails:
The text was updated successfully, but these errors were encountered: