shithub: hugo

Download patch

ref: a584ff207b4ee951e4b25cf5cedf6d261ee1bc47
parent: 599d1b9786ddbaa9203aaca2c96ab33b40a583b1
author: spf13 <[email protected]>
date: Tue May 19 22:21:21 EDT 2015

Stop Viper from leaking across many of the tests (now tests pass regardless of order tested)

--- a/commands/server_test.go
+++ b/commands/server_test.go
@@ -7,6 +7,8 @@
 )
 
 func TestFixURL(t *testing.T) {
+	defer viper.Reset()
+
 	type data struct {
 		TestName   string
 		CLIBaseURL string
@@ -28,6 +30,7 @@
 	}
 
 	for i, test := range tests {
+		viper.Reset()
 		BaseURL = test.CLIBaseURL
 		viper.Set("BaseURL", test.CfgBaseURL)
 		serverAppend = test.AppendPort
--- a/helpers/path_test.go
+++ b/helpers/path_test.go
@@ -431,6 +431,8 @@
 }
 
 func TestAbsPathify(t *testing.T) {
+	defer viper.Reset()
+
 	type test struct {
 		inPath, workingDir, expected string
 	}
@@ -450,6 +452,7 @@
 	}
 
 	for i, d := range data {
+		viper.Reset()
 		// todo see comment in AbsPathify
 		viper.Set("WorkingDir", d.workingDir)
 
--- a/helpers/pygments_test.go
+++ b/helpers/pygments_test.go
@@ -1,8 +1,9 @@
 package helpers
 
 import (
-	"github.com/spf13/viper"
 	"testing"
+
+	"github.com/spf13/viper"
 )
 
 func TestParsePygmentsArgs(t *testing.T) {
@@ -20,6 +21,7 @@
 		{"boo=invalid", "foo", false, false},
 		{"style", "foo", false, false},
 	} {
+		viper.Reset()
 		viper.Set("PygmentsStyle", this.pygmentsStyle)
 		viper.Set("PygmentsUseClasses", this.pygmentsUseClasses)
 
--- a/helpers/url_test.go
+++ b/helpers/url_test.go
@@ -1,10 +1,11 @@
 package helpers
 
 import (
-	"github.com/spf13/viper"
-	"github.com/stretchr/testify/assert"
 	"strings"
 	"testing"
+
+	"github.com/spf13/viper"
+	"github.com/stretchr/testify/assert"
 )
 
 func TestURLize(t *testing.T) {
@@ -28,6 +29,7 @@
 }
 
 func TestAbsURL(t *testing.T) {
+	defer viper.Reset()
 	tests := []struct {
 		input    string
 		baseURL  string
@@ -41,6 +43,7 @@
 	}
 
 	for _, test := range tests {
+		viper.Reset()
 		viper.Set("BaseURL", test.baseURL)
 		output := AbsURL(test.input)
 		if output != test.expected {
@@ -50,7 +53,8 @@
 }
 
 func TestRelURL(t *testing.T) {
-	defer viper.Set("canonifyURLs", viper.GetBool("canonifyURLs"))
+	defer viper.Reset()
+	//defer viper.Set("canonifyURLs", viper.GetBool("canonifyURLs"))
 	tests := []struct {
 		input    string
 		baseURL  string
@@ -70,6 +74,7 @@
 	}
 
 	for i, test := range tests {
+		viper.Reset()
 		viper.Set("BaseURL", test.baseURL)
 		viper.Set("canonifyURLs", test.canonify)
 
--- a/hugolib/menu_test.go
+++ b/hugolib/menu_test.go
@@ -5,13 +5,15 @@
 	"strings"
 	"testing"
 
+	"path/filepath"
+
 	"github.com/BurntSushi/toml"
+	"github.com/kr/pretty"
 	"github.com/spf13/afero"
 	"github.com/spf13/hugo/hugofs"
 	"github.com/spf13/hugo/source"
 	"github.com/spf13/viper"
 	"github.com/stretchr/testify/assert"
-	"path/filepath"
 )
 
 const (
@@ -156,6 +158,8 @@
 
 // Issue 817 - identifier should trump everything
 func TestPageMenuWithIdentifier(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
 
 	toml := []source.ByteSource{
 		{"sect/doc1.md", tstCreateMenuPageWithIdentifierTOML("t1", "m1", "i1")},
@@ -176,13 +180,12 @@
 
 func doTestPageMenuWithIdentifier(t *testing.T, menuPageSources []source.ByteSource) {
 
-	ts := setupMenuTests(t, menuPageSources)
-	defer resetMenuTestState(ts)
+	s := setupMenuTests(t, menuPageSources)
 
-	assert.Equal(t, 3, len(ts.site.Pages), "Not enough pages")
+	assert.Equal(t, 3, len(s.Pages), "Not enough pages")
 
-	me1 := ts.findTestMenuEntryByID("m1", "i1")
-	me2 := ts.findTestMenuEntryByID("m1", "i2")
+	me1 := findTestMenuEntryByID(s, "m1", "i1")
+	me2 := findTestMenuEntryByID(s, "m1", "i2")
 
 	assert.NotNil(t, me1)
 	assert.NotNil(t, me2)
@@ -194,6 +197,9 @@
 
 // Issue 817 contd - name should be second identifier in
 func TestPageMenuWithDuplicateName(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	toml := []source.ByteSource{
 		{"sect/doc1.md", tstCreateMenuPageWithNameTOML("t1", "m1", "n1")},
 		{"sect/doc2.md", tstCreateMenuPageWithNameTOML("t1", "m1", "n2")},
@@ -212,13 +218,12 @@
 }
 
 func doTestPageMenuWithDuplicateName(t *testing.T, menuPageSources []source.ByteSource) {
-	ts := setupMenuTests(t, menuPageSources)
-	defer resetMenuTestState(ts)
+	s := setupMenuTests(t, menuPageSources)
 
-	assert.Equal(t, 3, len(ts.site.Pages), "Not enough pages")
+	assert.Equal(t, 3, len(s.Pages), "Not enough pages")
 
-	me1 := ts.findTestMenuEntryByName("m1", "n1")
-	me2 := ts.findTestMenuEntryByName("m1", "n2")
+	me1 := findTestMenuEntryByName(s, "m1", "n1")
+	me2 := findTestMenuEntryByName(s, "m1", "n2")
 
 	assert.NotNil(t, me1)
 	assert.NotNil(t, me2)
@@ -229,19 +234,21 @@
 }
 
 func TestPageMenu(t *testing.T) {
-	ts := setupMenuTests(t, MENU_PAGE_SOURCES)
-	defer resetMenuTestState(ts)
+	viper.Reset()
+	defer viper.Reset()
 
-	if len(ts.site.Pages) != 3 {
-		t.Fatalf("Posts not created, expected 3 got %d", len(ts.site.Pages))
+	s := setupMenuTests(t, MENU_PAGE_SOURCES)
+
+	if len(s.Pages) != 3 {
+		t.Fatalf("Posts not created, expected 3 got %d", len(s.Pages))
 	}
 
-	first := ts.site.Pages[0]
-	second := ts.site.Pages[1]
-	third := ts.site.Pages[2]
+	first := s.Pages[0]
+	second := s.Pages[1]
+	third := s.Pages[2]
 
-	pOne := ts.findTestMenuEntryByName("p_one", "One")
-	pTwo := ts.findTestMenuEntryByID("p_two", "Two")
+	pOne := findTestMenuEntryByName(s, "p_one", "One")
+	pTwo := findTestMenuEntryByID(s, "p_two", "Two")
 
 	for i, this := range []struct {
 		menu           string
@@ -275,11 +282,13 @@
 
 // issue #888
 func TestMenuWithHashInURL(t *testing.T) {
-	ts := setupMenuTests(t, MENU_PAGE_SOURCES)
-	defer resetMenuTestState(ts)
+	viper.Reset()
+	defer viper.Reset()
 
-	me := ts.findTestMenuEntryByID("hash", "hash")
+	s := setupMenuTests(t, MENU_PAGE_SOURCES)
 
+	me := findTestMenuEntryByID(s, "hash", "hash")
+
 	assert.NotNil(t, me)
 
 	assert.Equal(t, "/Zoo/resource/#anchor", me.URL)
@@ -287,6 +296,9 @@
 
 // issue #719
 func TestMenuWithUnicodeURLs(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	for _, uglyURLs := range []bool{true, false} {
 		for _, canonifyURLs := range []bool{true, false} {
 			doTestMenuWithUnicodeURLs(t, canonifyURLs, uglyURLs)
@@ -298,10 +310,9 @@
 	viper.Set("CanonifyURLs", canonifyURLs)
 	viper.Set("UglyURLs", uglyURLs)
 
-	ts := setupMenuTests(t, MENU_PAGE_SOURCES)
-	defer resetMenuTestState(ts)
+	s := setupMenuTests(t, MENU_PAGE_SOURCES)
 
-	unicodeRussian := ts.findTestMenuEntryByID("unicode", "unicode-russian")
+	unicodeRussian := findTestMenuEntryByID(s, "unicode", "unicode-russian")
 
 	expectedBase := "/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B0"
 
@@ -321,31 +332,31 @@
 
 // Issue #1114
 func TestSectionPagesMenu(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	viper.Set("SectionPagesMenu", "spm")
-	defer viper.Set("SectionPagesMenu", "")
 
-	for _, canonify := range []bool{true, false} {
-		doTestSectionPagesMenu(canonify, t)
-	}
+	doTestSectionPagesMenu(true, t)
+	doTestSectionPagesMenu(false, t)
 }
 
 func doTestSectionPagesMenu(canonifyUrls bool, t *testing.T) {
 	viper.Set("CanonifyURLs", canonifyUrls)
-	ts := setupMenuTests(t, MENU_PAGE_SECTIONS_SOURCES)
-	defer resetMenuTestState(ts)
+	s := setupMenuTests(t, MENU_PAGE_SECTIONS_SOURCES)
 
-	assert.Equal(t, 2, len(ts.site.Sections))
+	assert.Equal(t, 2, len(s.Sections))
 
-	firstSectionPages := ts.site.Sections["first"]
+	firstSectionPages := s.Sections["first"]
 	assert.Equal(t, 2, len(firstSectionPages))
-	secondSectionPages := ts.site.Sections["second-section"]
+	secondSectionPages := s.Sections["second-section"]
 	assert.Equal(t, 1, len(secondSectionPages))
 
-	nodeFirst := ts.site.newSectionListNode("first", firstSectionPages)
-	nodeSecond := ts.site.newSectionListNode("second-section", secondSectionPages)
+	nodeFirst := s.newSectionListNode("first", firstSectionPages)
+	nodeSecond := s.newSectionListNode("second-section", secondSectionPages)
 
-	firstSectionMenuEntry := ts.findTestMenuEntryByID("spm", "first")
-	secondSectionMenuEntry := ts.findTestMenuEntryByID("spm", "second-section")
+	firstSectionMenuEntry := findTestMenuEntryByID(s, "spm", "first")
+	secondSectionMenuEntry := findTestMenuEntryByID(s, "spm", "second-section")
 
 	assert.NotNil(t, firstSectionMenuEntry)
 	assert.NotNil(t, secondSectionMenuEntry)
@@ -366,9 +377,11 @@
 }
 
 func TestTaxonomyNodeMenu(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	viper.Set("CanonifyURLs", true)
-	ts := setupMenuTests(t, MENU_PAGE_SOURCES)
-	defer resetMenuTestState(ts)
+	s := setupMenuTests(t, MENU_PAGE_SOURCES)
 
 	for i, this := range []struct {
 		menu           string
@@ -378,14 +391,14 @@
 		hasMenuCurrent bool
 	}{
 		{"tax", taxRenderInfo{key: "key", singular: "one", plural: "two"},
-			ts.findTestMenuEntryByID("tax", "1"), true, false},
+			findTestMenuEntryByID(s, "tax", "1"), true, false},
 		{"tax", taxRenderInfo{key: "key", singular: "one", plural: "two"},
-			ts.findTestMenuEntryByID("tax", "2"), true, false},
+			findTestMenuEntryByID(s, "tax", "2"), true, false},
 		{"tax", taxRenderInfo{key: "key", singular: "one", plural: "two"},
 			&MenuEntry{Name: "Somewhere else", URL: "/somewhereelse"}, false, false},
 	} {
 
-		n, _ := ts.site.newTaxonomyNode(this.taxInfo)
+		n, _ := s.newTaxonomyNode(this.taxInfo)
 
 		isMenuCurrent := n.IsMenuCurrent(this.menu, this.menuItem)
 		hasMenuCurrent := n.HasMenuCurrent(this.menu, this.menuItem)
@@ -400,7 +413,7 @@
 
 	}
 
-	menuEntryXML := ts.findTestMenuEntryByID("tax", "xml")
+	menuEntryXML := findTestMenuEntryByID(s, "tax", "xml")
 
 	if strings.HasSuffix(menuEntryXML.URL, "/") {
 		t.Error("RSS menu item should not be padded with trailing slash")
@@ -408,10 +421,15 @@
 }
 
 func TestHomeNodeMenu(t *testing.T) {
-	ts := setupMenuTests(t, MENU_PAGE_SOURCES)
-	defer resetMenuTestState(ts)
+	viper.Reset()
+	defer viper.Reset()
 
-	home := ts.site.newHomeNode()
+	viper.Set("CanonifyURLs", true)
+	viper.Set("UglyURLs", true)
+
+	s := setupMenuTests(t, MENU_PAGE_SOURCES)
+
+	home := s.newHomeNode()
 	homeMenuEntry := &MenuEntry{Name: home.Title, URL: home.URL}
 
 	for i, this := range []struct {
@@ -423,9 +441,9 @@
 		{"main", homeMenuEntry, true, false},
 		{"doesnotexist", homeMenuEntry, false, false},
 		{"main", &MenuEntry{Name: "Somewhere else", URL: "/somewhereelse"}, false, false},
-		{"grandparent", ts.findTestMenuEntryByID("grandparent", "grandparentId"), false, false},
-		{"grandparent", ts.findTestMenuEntryByID("grandparent", "parentId"), false, true},
-		{"grandparent", ts.findTestMenuEntryByID("grandparent", "grandchildId"), true, false},
+		{"grandparent", findTestMenuEntryByID(s, "grandparent", "grandparentId"), false, false},
+		{"grandparent", findTestMenuEntryByID(s, "grandparent", "parentId"), false, true},
+		{"grandparent", findTestMenuEntryByID(s, "grandparent", "grandchildId"), true, false},
 	} {
 
 		isMenuCurrent := home.IsMenuCurrent(this.menu, this.menuItem)
@@ -432,11 +450,15 @@
 		hasMenuCurrent := home.HasMenuCurrent(this.menu, this.menuItem)
 
 		if isMenuCurrent != this.isMenuCurrent {
-			t.Errorf("[%d] Wrong result from IsMenuCurrent: %v", i, isMenuCurrent)
+			fmt.Println("isMenuCurrent", isMenuCurrent)
+			pretty.Println("this:", this)
+			t.Errorf("[%d] Wrong result from IsMenuCurrent: %v for %q", i, isMenuCurrent, this.menu)
 		}
 
 		if hasMenuCurrent != this.hasMenuCurrent {
-			t.Errorf("[%d] Wrong result for menuItem %v for HasMenuCurrent: %v", i, this.menuItem, hasMenuCurrent)
+			fmt.Println("hasMenuCurrent", hasMenuCurrent)
+			pretty.Println("this:", this)
+			t.Errorf("[%d] Wrong result for menu %q menuItem %v for HasMenuCurrent: %v", i, this.menu, this.menuItem, hasMenuCurrent)
 		}
 	}
 }
@@ -444,16 +466,16 @@
 var testMenuIdentityMatcher = func(me *MenuEntry, id string) bool { return me.Identifier == id }
 var testMenuNameMatcher = func(me *MenuEntry, id string) bool { return me.Name == id }
 
-func (ts testMenuState) findTestMenuEntryByID(mn string, id string) *MenuEntry {
-	return ts.findTestMenuEntry(mn, id, testMenuIdentityMatcher)
+func findTestMenuEntryByID(s *Site, mn string, id string) *MenuEntry {
+	return findTestMenuEntry(s, mn, id, testMenuIdentityMatcher)
 }
-func (ts testMenuState) findTestMenuEntryByName(mn string, id string) *MenuEntry {
-	return ts.findTestMenuEntry(mn, id, testMenuNameMatcher)
+func findTestMenuEntryByName(s *Site, mn string, id string) *MenuEntry {
+	return findTestMenuEntry(s, mn, id, testMenuNameMatcher)
 }
 
-func (ts testMenuState) findTestMenuEntry(mn string, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
+func findTestMenuEntry(s *Site, mn string, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
 	var found *MenuEntry
-	if menu, ok := ts.site.Menus[mn]; ok {
+	if menu, ok := s.Menus[mn]; ok {
 		for _, me := range *menu {
 
 			if matcher(me, id) {
@@ -463,7 +485,7 @@
 				found = me
 			}
 
-			descendant := ts.findDescendantTestMenuEntry(me, id, matcher)
+			descendant := findDescendantTestMenuEntry(me, id, matcher)
 			if descendant != nil {
 				if found != nil {
 					panic(fmt.Sprintf("Duplicate menu entry in menu %s with id/name %s", mn, id))
@@ -475,7 +497,7 @@
 	return found
 }
 
-func (ts testMenuState) findDescendantTestMenuEntry(parent *MenuEntry, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
+func findDescendantTestMenuEntry(parent *MenuEntry, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
 	var found *MenuEntry
 	if parent.HasChildren() {
 		for _, child := range parent.Children {
@@ -487,7 +509,7 @@
 				found = child
 			}
 
-			descendant := ts.findDescendantTestMenuEntry(child, id, matcher)
+			descendant := findDescendantTestMenuEntry(child, id, matcher)
 			if descendant != nil {
 				if found != nil {
 					panic(fmt.Sprintf("Duplicate menu entry in menuitem %s with id/name %s", parent.KeyName(), id))
@@ -499,9 +521,7 @@
 	return found
 }
 
-func getTestMenuState(s *Site, t *testing.T) *testMenuState {
-	menuState := &testMenuState{site: s, oldBaseURL: viper.Get("baseurl"), oldMenu: viper.Get("menu")}
-
+func setupTestMenuState(s *Site, t *testing.T) {
 	menus, err := tomlToMap(CONF_MENU1)
 
 	if err != nil {
@@ -510,23 +530,16 @@
 
 	viper.Set("menu", menus["menu"])
 	viper.Set("baseurl", "http://foo.local/Zoo/")
-
-	return menuState
 }
 
-func setupMenuTests(t *testing.T, pageSources []source.ByteSource) *testMenuState {
+func setupMenuTests(t *testing.T, pageSources []source.ByteSource) *Site {
 	s := createTestSite(pageSources)
-	testState := getTestMenuState(s, t)
+	setupTestMenuState(s, t)
 	testSiteSetup(s, t)
 
-	return testState
+	return s
 }
 
-func resetMenuTestState(state *testMenuState) {
-	viper.Set("menu", state.oldMenu)
-	viper.Set("baseurl", state.oldBaseURL)
-}
-
 func createTestSite(pageSources []source.ByteSource) *Site {
 	hugofs.DestinationFS = new(afero.MemMapFs)
 
@@ -537,7 +550,6 @@
 }
 
 func testSiteSetup(s *Site, t *testing.T) {
-
 	s.Menus = Menus{}
 	s.initializeSiteInfo()
 
@@ -548,7 +560,6 @@
 	if err := s.BuildSiteMeta(); err != nil {
 		t.Fatalf("Unable to build site metadata: %s", err)
 	}
-
 }
 
 func tomlToMap(s string) (map[string]interface{}, error) {
--- a/hugolib/page_permalink_test.go
+++ b/hugolib/page_permalink_test.go
@@ -10,6 +10,9 @@
 )
 
 func TestPermalink(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	tests := []struct {
 		file         string
 		dir          string
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -10,6 +10,7 @@
 
 	"github.com/spf13/cast"
 	"github.com/spf13/hugo/helpers"
+	"github.com/spf13/viper"
 )
 
 var EMPTY_PAGE = ""
@@ -664,15 +665,19 @@
 }
 
 func TestTargetPath(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
+	viper.Set("DefaultExtension", "html")
 	site_permalinks_setting := PermalinkOverrides{
 		"post": ":year/:month/:day/:title/",
 	}
 
 	tests := []struct {
-		content        string
-		path           string
-		hasPermalink   bool
-		expected       string
+		content      string
+		path         string
+		hasPermalink bool
+		expected     string
 	}{
 		{SIMPLE_PAGE, "content/post/x.md", false, "content/post/x.html"},
 		{SIMPLE_PAGE_WITH_URL, "content/post/x.md", false, "simple/url/index.html"},
--- a/hugolib/pagination_test.go
+++ b/hugolib/pagination_test.go
@@ -2,12 +2,13 @@
 
 import (
 	"fmt"
-	"github.com/spf13/hugo/source"
-	"github.com/spf13/viper"
-	"github.com/stretchr/testify/assert"
 	"html/template"
 	"path/filepath"
 	"testing"
+
+	"github.com/spf13/hugo/source"
+	"github.com/spf13/viper"
+	"github.com/stretchr/testify/assert"
 )
 
 func TestSplitPages(t *testing.T) {
@@ -100,6 +101,9 @@
 }
 
 func TestPaginationURLFactory(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	viper.Set("PaginatePath", "zoo")
 	unicode := newPaginationURLFactory("новости проекта")
 	fooBar := newPaginationURLFactory("foo", "bar")
@@ -112,6 +116,9 @@
 }
 
 func TestPaginator(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	for _, useViper := range []bool{false, true} {
 		doTestPaginator(t, useViper)
 	}
@@ -118,6 +125,9 @@
 }
 
 func doTestPaginator(t *testing.T, useViper bool) {
+	viper.Reset()
+	defer viper.Reset()
+
 	pagerSize := 5
 	if useViper {
 		viper.Set("paginate", pagerSize)
@@ -159,6 +169,9 @@
 }
 
 func TestPaginatorWithNegativePaginate(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	viper.Set("paginate", -1)
 	s := &Site{}
 	_, err := s.newHomeNode().Paginator()
@@ -166,6 +179,9 @@
 }
 
 func TestPaginate(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	for _, useViper := range []bool{false, true} {
 		doTestPaginate(t, useViper)
 	}
@@ -224,6 +240,9 @@
 }
 
 func TestPaginateWithNegativePaginate(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	viper.Set("paginate", -1)
 	s := &Site{}
 	_, err := s.newHomeNode().Paginate(createTestPages(2))
@@ -243,6 +262,9 @@
 
 // Issue #993
 func TestPaginatorFollowedByPaginateShouldFail(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	viper.Set("paginate", 10)
 	s := &Site{}
 	n1 := s.newHomeNode()
@@ -259,6 +281,8 @@
 }
 
 func TestPaginateFollowedByDifferentPaginateShouldFail(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
 
 	viper.Set("paginate", 10)
 	s := &Site{}
--- a/hugolib/rss_test.go
+++ b/hugolib/rss_test.go
@@ -33,10 +33,12 @@
 </rss>`
 
 func TestRSSOutput(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	rssUri := "customrss.xml"
 	viper.Set("baseurl", "http://auth/bub/")
 	viper.Set("RSSUri", rssUri)
-	defer viper.Set("RSSUri", "index.xml")
 
 	hugofs.DestinationFS = new(afero.MemMapFs)
 	s := &Site{
@@ -44,6 +46,7 @@
 	}
 	s.initializeSiteInfo()
 	s.prepTemplates()
+
 	//  Add an rss.xml template to invoke the rss build.
 	s.addTemplate("rss.xml", RSS_TEMPLATE)
 
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -177,10 +177,12 @@
 }
 
 func TestHighlight(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	if !helpers.HasPygments() {
 		t.Skip("Skip test as Pygments is not installed")
 	}
-	defer viper.Set("PygmentsStyle", viper.Get("PygmentsStyle"))
 	viper.Set("PygmentsStyle", "bw")
 
 	tem := tpl.New()
--- a/hugolib/site_show_plan_test.go
+++ b/hugolib/site_show_plan_test.go
@@ -2,12 +2,14 @@
 
 import (
 	"bytes"
-	"github.com/spf13/hugo/helpers"
-	"github.com/spf13/hugo/source"
-	"github.com/spf13/hugo/target"
 	"path/filepath"
 	"strings"
 	"testing"
+
+	"github.com/spf13/hugo/helpers"
+	"github.com/spf13/hugo/source"
+	"github.com/spf13/hugo/target"
+	"github.com/spf13/viper"
 )
 
 const ALIAS_DOC_1 = "---\ntitle: alias doc\naliases:\n  - \"alias1/\"\n  - \"alias-2/\"\n---\naliases\n"
@@ -74,6 +76,11 @@
 }
 
 func TestFileTarget(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
+	viper.Set("DefaultExtension", "html")
+
 	s := &Site{
 		Source: &source.InMemorySource{ByteSource: fakeSource},
 	}
@@ -91,6 +98,11 @@
 }
 
 func TestPageTargetUgly(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+	viper.Set("DefaultExtension", "html")
+	viper.Set("UglyURLs", true)
+
 	s := &Site{
 		Targets: targetList{Page: &target.PagePub{UglyURLs: true}},
 		Source:  &source.InMemorySource{ByteSource: fakeSource},
@@ -108,6 +120,10 @@
 }
 
 func TestFileTargetPublishDir(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+	viper.Set("DefaultExtension", "html")
+
 	s := &Site{
 
 		Targets: targetList{
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -3,6 +3,12 @@
 import (
 	"bytes"
 	"fmt"
+	"html/template"
+	"io"
+	"path/filepath"
+	"strings"
+	"testing"
+
 	"github.com/spf13/afero"
 	"github.com/spf13/hugo/helpers"
 	"github.com/spf13/hugo/hugofs"
@@ -10,11 +16,6 @@
 	"github.com/spf13/hugo/target"
 	"github.com/spf13/hugo/tpl"
 	"github.com/spf13/viper"
-	"html/template"
-	"io"
-	"path/filepath"
-	"strings"
-	"testing"
 )
 
 const (
@@ -212,8 +213,10 @@
 	}
 }
 
-
 func TestDraftAndFutureRender(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	hugofs.DestinationFS = new(afero.MemMapFs)
 	sources := []source.ByteSource{
 		{filepath.FromSlash("sect/doc1.md"), []byte("---\ntitle: doc1\ndraft: true\npublishdate: \"2414-05-29\"\n---\n# doc1\n*some content*")},
@@ -281,7 +284,11 @@
 }
 
 func doTestCrossrefs(t *testing.T, relative, uglyUrls bool) {
+	viper.Reset()
+	defer viper.Reset()
+
 	baseUrl := "http://foo/bar"
+	viper.Set("DefaultExtension", "html")
 	viper.Set("baseurl", baseUrl)
 	viper.Set("UglyURLs", uglyUrls)
 	viper.Set("verbose", true)
@@ -358,10 +365,15 @@
 }
 
 func doTest404ShouldAlwaysHaveUglyUrls(t *testing.T, uglyURLs bool) {
+	viper.Reset()
+	defer viper.Reset()
+
+	viper.Set("DefaultExtension", "html")
 	viper.Set("verbose", true)
 	viper.Set("baseurl", "http://auth/bub")
 	viper.Set("DisableSitemap", false)
 	viper.Set("DisableRSS", false)
+	viper.Set("RSSUri", "index.xml")
 
 	viper.Set("UglyURLs", uglyURLs)
 
@@ -423,6 +435,9 @@
 }
 
 func TestSkipRender(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	hugofs.DestinationFS = new(afero.MemMapFs)
 	sources := []source.ByteSource{
 		{filepath.FromSlash("sect/doc1.html"), []byte("---\nmarkup: markdown\n---\n# title\nsome *content*")},
@@ -435,6 +450,7 @@
 		{filepath.FromSlash("sect/doc8.html"), []byte("---\nmarkup: md\n---\n# title\nsome *content*")},
 	}
 
+	viper.Set("DefaultExtension", "html")
 	viper.Set("verbose", true)
 	viper.Set("CanonifyURLs", true)
 	viper.Set("baseurl", "http://auth/bub")
@@ -481,6 +497,11 @@
 }
 
 func TestAbsUrlify(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
+	viper.Set("DefaultExtension", "html")
+
 	hugofs.DestinationFS = new(afero.MemMapFs)
 	sources := []source.ByteSource{
 		{filepath.FromSlash("sect/doc1.html"), []byte("<!doctype html><html><head></head><body><a href=\"#frag1\">link</a></body></html>")},
@@ -584,6 +605,9 @@
 }
 
 func TestOrderedPages(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	hugofs.DestinationFS = new(afero.MemMapFs)
 
 	viper.Set("baseurl", "http://auth/bub")
@@ -649,6 +673,9 @@
 }
 
 func TestGroupedPages(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	defer func() {
 		if r := recover(); r != nil {
 			fmt.Println("Recovered in f", r)
@@ -832,6 +859,9 @@
 Front Matter with weighted tags and categories`)
 
 func TestWeightedTaxonomies(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	hugofs.DestinationFS = new(afero.MemMapFs)
 	sources := []source.ByteSource{
 		{filepath.FromSlash("sect/doc1.md"), PAGE_WITH_WEIGHTED_TAXONOMIES_1},
--- a/hugolib/site_url_test.go
+++ b/hugolib/site_url_test.go
@@ -4,12 +4,13 @@
 	"path/filepath"
 	"testing"
 
+	"html/template"
+
 	"github.com/spf13/afero"
 	"github.com/spf13/hugo/hugofs"
 	"github.com/spf13/hugo/source"
 	"github.com/spf13/hugo/target"
 	"github.com/spf13/viper"
-	"html/template"
 )
 
 const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\naliases:\n - sd1/foo/\n - sd2\n - sd3/\n - sd4.html\n---\nslug doc 1 content\n"
@@ -54,6 +55,8 @@
 
 // Issue #1105
 func TestShouldNotAddTrailingSlashToBaseURL(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
 
 	for i, this := range []struct {
 		in       string
@@ -76,6 +79,9 @@
 }
 
 func TestPageCount(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	hugofs.DestinationFS = new(afero.MemMapFs)
 
 	viper.Set("uglyurls", false)
--- a/hugolib/siteinfo_test.go
+++ b/hugolib/siteinfo_test.go
@@ -10,6 +10,9 @@
 const SITE_INFO_PARAM_TEMPLATE = `{{ .Site.Params.MyGlobalParam }}`
 
 func TestSiteInfoParams(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	viper.Set("Params", map[string]interface{}{"MyGlobalParam": "FOOBAR_PARAM"})
 	s := &Site{}
 
@@ -32,6 +35,9 @@
 }
 
 func TestSiteInfoPermalinks(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	viper.Set("Permalinks", map[string]interface{}{"section": "/:title"})
 	s := &Site{}
 
--- a/hugolib/sitemap_test.go
+++ b/hugolib/sitemap_test.go
@@ -23,6 +23,9 @@
 </urlset>`
 
 func TestSitemapOutput(t *testing.T) {
+	viper.Reset()
+	defer viper.Reset()
+
 	hugofs.DestinationFS = new(afero.MemMapFs)
 
 	viper.Set("baseurl", "http://auth/bub/")