Keep Homebrew site-packages in sys.path during brew test

Formulas that build python things and which are tested with system
Python will encounter test failures unless system Python is configured
to add Homebrew's site-packages to sys.path. This change makes sure that
configuration is performed in the test environment.

Both lines are needed; the first reads and processes .pth files and the
second makes sure that Homebrew's site-packages is read before the
system extras, so that formulas depending on Homebrew/python/numpy get
the Homebrew/python version and not the old system version.

Closes Homebrew/homebrew#38466.
This commit is contained in:
Tim D. Smith 2015-04-08 12:56:32 -07:00
parent f5c8e3fdbd
commit a5e1f698d5

View File

@ -634,6 +634,7 @@ class Formula
mktemp do mktemp do
@testpath = Pathname.pwd @testpath = Pathname.pwd
ENV["HOME"] = @testpath ENV["HOME"] = @testpath
setup_test_home @testpath
test test
end end
ensure ensure
@ -658,6 +659,16 @@ class Formula
protected protected
def setup_test_home home
# keep Homebrew's site-packages in sys.path when testing with system Python
user_site_packages = home/"Library/Python/2.7/lib/python/site-packages"
user_site_packages.mkpath
(user_site_packages/"homebrew.pth").write <<-EOS.undent
import site; site.addsitedir("#{HOMEBREW_PREFIX}/lib/python2.7/site-packages")
import sys; sys.path.insert(0, "#{HOMEBREW_PREFIX}/lib/python2.7/site-packages")
EOS
end
# Pretty titles the command and buffers stdout/stderr # Pretty titles the command and buffers stdout/stderr
# Throws if there's an error # Throws if there's an error
def system cmd, *args def system cmd, *args