
import os
import pytest
import subprocess

from cookiecutter import utils


def test_should_raise_error_without_template_arg(capfd):
    with pytest.raises(subprocess.CalledProcessError):
        subprocess.check_call(['python', '-m', 'cookiecutter.cli'])

    _, err = capfd.readouterr()
    exp_message = 'Error: Missing argument "template".'
    assert exp_message in err


@pytest.fixture
def project_dir(request):
    """Remove the rendered project directory created by the test."""
    rendered_dir = 'fake-project-templated'

    def remove_generated_project():
        if os.path.isdir(rendered_dir):
            utils.rmtree(rendered_dir)
    request.addfinalizer(remove_generated_project)

    return rendered_dir


def test_should_invoke_main(project_dir):
    subprocess.check_call([
        'python',
        '-m',
        'cookiecutter.cli',
        'tests/fake-repo-tmpl',
        '--no-input'
    ])
    assert os.path.isdir(project_dir)


import os
import pytest
import subprocess
import sys

from cookiecutter import utils


def test_should_raise_error_without_template_arg(capfd):
    with pytest.raises(subprocess.CalledProcessError):
        subprocess.check_call(['python', '-m', 'cookiecutter.cli'])

    _, err = capfd.readouterr()
    exp_message = 'Error: Missing argument "template".'
    assert exp_message in err


@pytest.fixture
def project_dir(request):
    """Remove the rendered project directory created by the test."""
    rendered_dir = 'fake-project-templated'

    def remove_generated_project():
        if os.path.isdir(rendered_dir):
            utils.rmtree(rendered_dir)
    request.addfinalizer(remove_generated_project)

    return rendered_dir


def test_should_invoke_main(monkeypatch, project_dir):
    monkeypatch.setenv('PYTHONPATH', '.')

    subprocess.check_call([
        sys.executable,
        '-m',
        'cookiecutter.cli',
        'tests/fake-repo-tmpl',
        '--no-input'
    ])

    assert os.path.isdir(project_dir)

Set PYTHONPATH and use sys.executable
Set PYTHONPATH and use sys.executable

  
  import os
  import pytest
  import subprocess
+ import sys
  
  from cookiecutter import utils
  
  
  def test_should_raise_error_without_template_arg(capfd):
      with pytest.raises(subprocess.CalledProcessError):
          subprocess.check_call(['python', '-m', 'cookiecutter.cli'])
  
      _, err = capfd.readouterr()
      exp_message = 'Error: Missing argument "template".'
      assert exp_message in err
  
  
  @pytest.fixture
  def project_dir(request):
      """Remove the rendered project directory created by the test."""
      rendered_dir = 'fake-project-templated'
  
      def remove_generated_project():
          if os.path.isdir(rendered_dir):
              utils.rmtree(rendered_dir)
      request.addfinalizer(remove_generated_project)
  
      return rendered_dir
  
  
- def test_should_invoke_main(project_dir):
+ def test_should_invoke_main(monkeypatch, project_dir):
+     monkeypatch.setenv('PYTHONPATH', '.')
+ 
      subprocess.check_call([
-         'python',
+         sys.executable,
          '-m',
          'cookiecutter.cli',
          'tests/fake-repo-tmpl',
          '--no-input'
      ])
+ 
      assert os.path.isdir(project_dir)
  
Set PYTHONPATH and use sys.executable
## Code Before:

import os
import pytest
import subprocess

from cookiecutter import utils


def test_should_raise_error_without_template_arg(capfd):
    with pytest.raises(subprocess.CalledProcessError):
        subprocess.check_call(['python', '-m', 'cookiecutter.cli'])

    _, err = capfd.readouterr()
    exp_message = 'Error: Missing argument "template".'
    assert exp_message in err


@pytest.fixture
def project_dir(request):
    """Remove the rendered project directory created by the test."""
    rendered_dir = 'fake-project-templated'

    def remove_generated_project():
        if os.path.isdir(rendered_dir):
            utils.rmtree(rendered_dir)
    request.addfinalizer(remove_generated_project)

    return rendered_dir


def test_should_invoke_main(project_dir):
    subprocess.check_call([
        'python',
        '-m',
        'cookiecutter.cli',
        'tests/fake-repo-tmpl',
        '--no-input'
    ])
    assert os.path.isdir(project_dir)

## Instruction:
Set PYTHONPATH and use sys.executable
## Code After:

import os
import pytest
import subprocess
import sys

from cookiecutter import utils


def test_should_raise_error_without_template_arg(capfd):
    with pytest.raises(subprocess.CalledProcessError):
        subprocess.check_call(['python', '-m', 'cookiecutter.cli'])

    _, err = capfd.readouterr()
    exp_message = 'Error: Missing argument "template".'
    assert exp_message in err


@pytest.fixture
def project_dir(request):
    """Remove the rendered project directory created by the test."""
    rendered_dir = 'fake-project-templated'

    def remove_generated_project():
        if os.path.isdir(rendered_dir):
            utils.rmtree(rendered_dir)
    request.addfinalizer(remove_generated_project)

    return rendered_dir


def test_should_invoke_main(monkeypatch, project_dir):
    monkeypatch.setenv('PYTHONPATH', '.')

    subprocess.check_call([
        sys.executable,
        '-m',
        'cookiecutter.cli',
        'tests/fake-repo-tmpl',
        '--no-input'
    ])

    assert os.path.isdir(project_dir)
