Repository: go-swagger/go-swagger
Pull request #2450 (2020-12-06 12:58:00)

test: model tests go parallel
* updated go-openapi dependencies to fix race conditions on parallel spec processing
* adapted tests to process fixtures in parallel
* refactored tests for readability (e.g. require... instead of if assert...)
* fixed race condition on global templates when testing in parallel:
   * templates are now a shadow clone in GenOpts: now generation can proceed in parallel, even with contrib templates
     (custom templates from config remain loaded in the global templates)

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>

codecov[bot]: # [Codecov](https://codecov.io/gh/go-swagger/go-swagger/pull/2450?src=pr&el=h1) Report
> Merging [#2450](https://codecov.io/gh/go-swagger/go-swagger/pull/2450?src=pr&el=desc) (dda9ae7) into [master](https://codecov.io/gh/go-swagger/go-swagger/commit/6b597d4e072ab226e2e68d778ee6ed9fd9a46283?el=desc) (6b597d4) will **decrease** coverage by `0.34%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/go-swagger/go-swagger/pull/2450/graphs/tree.svg?width=650&height=150&src=pr&token=aQS1DepR8C)](https://codecov.io/gh/go-swagger/go-swagger/pull/2450?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #2450      +/-   ##
==========================================
- Coverage   82.07%   81.73%   -0.35%     
==========================================
  Files          52       52              
  Lines        8201     8212      +11     
==========================================
- Hits         6731     6712      -19     
- Misses        990     1010      +20     
- Partials      480      490      +10     
```


| [Impacted Files](https://codecov.io/gh/go-swagger/go-swagger/pull/2450?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [generator/shared.go](https://codecov.io/gh/go-swagger/go-swagger/pull/2450/diff?src=pr&el=tree#diff-Z2VuZXJhdG9yL3NoYXJlZC5nbw==) | `88.68% <100.00%> (+0.02%)` | :arrow_up: |
| [generator/support.go](https://codecov.io/gh/go-swagger/go-swagger/pull/2450/diff?src=pr&el=tree#diff-Z2VuZXJhdG9yL3N1cHBvcnQuZ28=) | `87.05% <100.00%> (+0.05%)` | :arrow_up: |
| [generator/template\_repo.go](https://codecov.io/gh/go-swagger/go-swagger/pull/2450/diff?src=pr&el=tree#diff-Z2VuZXJhdG9yL3RlbXBsYXRlX3JlcG8uZ28=) | `94.24% <100.00%> (+0.19%)` | :arrow_up: |
| [generator/types.go](https://codecov.io/gh/go-swagger/go-swagger/pull/2450/diff?src=pr&el=tree#diff-Z2VuZXJhdG9yL3R5cGVzLmdv) | `87.74% <0.00%> (-4.28%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/go-swagger/go-swagger/pull/2450?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/go-swagger/go-swagger/pull/2450?src=pr&el=footer). Last update [6b597d4...dda9ae7](https://codecov.io/gh/go-swagger/go-swagger/pull/2450?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/fixtures/bugs/1897/.gitignore b/fixtures/bugs/1897/.gitignore
new file mode 100644
index 00000000..6f104396
--- /dev/null
+++ b/fixtures/bugs/1897/.gitignore
@@ -0,0 +1,1 @@
+external/
diff --git a/generator/.gitignore b/generator/.gitignore
new file mode 100644
index 00000000..9ab870da
--- /dev/null
+++ b/generator/.gitignore
@@ -0,0 +1,1 @@
+generated/
diff --git a/generator/shared.go b/generator/shared.go
index e23cd17c..a9de8930 100644
--- a/generator/shared.go
+++ b/generator/shared.go
@@ -269,6 +269,8 @@ type GenOpts struct {
 	AllowEnumCI            bool
 	StrictResponders       bool
 	AcceptDefinitionsOnly  bool
+
+	templates *Repository // a shallow clone of the global template repository
 }
 
 // CheckOpts carries out some global consistency checks on options.
@@ -366,7 +368,7 @@ func (g *GenOpts) SpecPath() string {
 // PrincipalIsNullable indicates whether the principal type used for authentication
 // may be used as a pointer
 func (g *GenOpts) PrincipalIsNullable() bool {
-	log.Printf("Principal: %s, %t, isnullable: %t", g.Principal, g.PrincipalCustomIface, g.Principal != iface && !g.PrincipalCustomIface)
+	debugLog("Principal: %s, %t, isnullable: %t", g.Principal, g.PrincipalCustomIface, g.Principal != iface && !g.PrincipalCustomIface)
 	return g.Principal != iface && !g.PrincipalCustomIface
 }
 
@@ -376,6 +378,10 @@ func (g *GenOpts) EnsureDefaults() error {
 		return nil
 	}
 
+	g.templates = templates.ShallowClone()
+
+	g.templates.LoadDefaults()
+
 	if g.LanguageOpts == nil {
 		g.LanguageOpts = DefaultLanguageFunc()
 	}
@@ -491,7 +497,7 @@ func (g *GenOpts) render(t *TemplateOpts, data interface{}) ([]byte, error) {
 	var templ *template.Template
 
 	if strings.HasPrefix(strings.ToLower(t.Source), "asset:") {
-		tt, err := templates.Get(strings.TrimPrefix(t.Source, "asset:"))
+		tt, err := g.templates.Get(strings.TrimPrefix(t.Source, "asset:"))
 		if err != nil {
 			return nil, err
 		}
@@ -501,7 +507,7 @@ func (g *GenOpts) render(t *TemplateOpts, data interface{}) ([]byte, error) {
 	if templ == nil {
 		// try to load from repository (and enable dependencies)
 		name := swag.ToJSONName(strings.TrimSuffix(t.Source, ".gotmpl"))
-		tt, err := templates.Get(name)
+		tt, err := g.templates.Get(name)
 		if err == nil {
 			templ = tt
 		}
@@ -674,20 +680,18 @@ func (g *GenOpts) renderDefinition(gg *GenDefinition) error {
 }
 
 func (g *GenOpts) setTemplates() error {
-	templates.LoadDefaults()
-
 	if g.Template != "" {
 		// set contrib templates
-		if err := templates.LoadContrib(g.Template); err != nil {
+		if err := g.templates.LoadContrib(g.Template); err != nil {
 			return err
 		}
 	}
 
-	templates.SetAllowOverride(g.AllowTemplateOverride)
+	g.templates.SetAllowOverride(g.AllowTemplateOverride)
 
 	if g.TemplateDir != "" {
 		// set custom templates
-		if err := templates.LoadDir(g.TemplateDir); err != nil {
+		if err := g.templates.LoadDir(g.TemplateDir); err != nil {
 			return err
 		}
 	}
diff --git a/generator/support.go b/generator/support.go
index d8eb1713..47464acb 100644
--- a/generator/support.go
+++ b/generator/support.go
@@ -229,7 +229,7 @@ func (a *appGenerator) makeCodegenApp() (GenApp, error) {
 		baseImport,
 		a.GenOpts.LanguageOpts.ManglePackagePath(a.OperationsPackage, defaultOperationsTarget))
 
-	log.Println("planning definitions")
+	log.Printf("planning definitions (found: %d)", len(a.Models))
 
 	genModels := make(GenDefinitions, 0, len(a.Models))
 	for mn, m := range a.Models {
@@ -258,7 +258,7 @@ func (a *appGenerator) makeCodegenApp() (GenApp, error) {
 	}
 	sort.Sort(genModels)
 
-	log.Println("planning operations")
+	log.Printf("planning operations (found: %d)", len(a.Operations))
 
 	genOps := make(GenOperations, 0, len(a.Operations))
 	for operationName, opp := range a.Operations {
@@ -326,15 +326,16 @@ func (a *appGenerator) makeCodegenApp() (GenApp, error) {
 	}
 	sort.Sort(genOps)
 
-	log.Println("grouping operations into packages")
-
 	opsGroupedByPackage := make(map[string]GenOperations, len(genOps))
 	for _, operation := range genOps {
 		opsGroupedByPackage[operation.PackageAlias] = append(opsGroupedByPackage[operation.PackageAlias], operation)
 	}
 
+	log.Printf("grouping operations into packages (packages: %d)", len(opsGroupedByPackage))
+
 	opGroups := make(GenOperationGroups, 0, len(opsGroupedByPackage))
 	for k, v := range opsGroupedByPackage {
+		log.Printf("operations for package packages %q (found: %d)", k, len(v))
 		sort.Sort(v)
 		// trim duplicate extra schemas within the same package
 		vv := make(GenOperations, 0, len(v))
diff --git a/generator/template_repo.go b/generator/template_repo.go
index ba644d7f..73ced57d 100644
--- a/generator/template_repo.go
+++ b/generator/template_repo.go
@@ -9,6 +9,7 @@ import (
 	"path"
 	"path/filepath"
 	"strings"
+	"sync"
 	"text/template"
 	"text/template/parse"
 	"unicode"
@@ -216,6 +217,31 @@ type Repository struct {
 	templates     map[string]*template.Template
 	funcs         template.FuncMap
 	allowOverride bool
+	mux           sync.Mutex
+}
+
+// ShallowClone a repository.
+//
+// Clones the maps of files and templates, so as to be able to use
+// the cloned repo concurrently.
+func (t *Repository) ShallowClone() *Repository {
+	clone := &Repository{
+		files:         make(map[string]string, len(t.files)),
+		templates:     make(map[string]*template.Template, len(t.templates)),
+		funcs:         t.funcs,
+		allowOverride: t.allowOverride,
+	}
+
+	t.mux.Lock()
+	defer t.mux.Unlock()
+
+	for k, file := range t.files {
+		clone.files[k] = file
+	}
+	for k, tpl := range t.templates {
+		clone.templates[k] = tpl
+	}
+	return clone
 }
 
 // LoadDefaults will load the embedded templates
diff --git a/go.mod b/go.mod
index 406582df..a3006a1c 100644
--- a/go.mod
+++ b/go.mod
@@ -10,12 +10,12 @@ require (
 	github.com/go-openapi/analysis v0.19.16
 	github.com/go-openapi/errors v0.19.9
 	github.com/go-openapi/inflect v0.19.0
-	github.com/go-openapi/loads v0.19.7
+	github.com/go-openapi/loads v0.20.0
 	github.com/go-openapi/runtime v0.19.24
-	github.com/go-openapi/spec v0.19.15
+	github.com/go-openapi/spec v0.20.0
 	github.com/go-openapi/strfmt v0.19.11
 	github.com/go-openapi/swag v0.19.12
-	github.com/go-openapi/validate v0.19.15
+	github.com/go-openapi/validate v0.20.0
 	github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013
 	github.com/golang/protobuf v1.4.3 // indirect
 	github.com/gorilla/handlers v1.5.1
@@ -34,7 +34,7 @@ require (
 	github.com/stretchr/testify v1.6.1
 	github.com/toqueteos/webbrowser v1.2.0
 	golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392 // indirect
-	golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
+	golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb
 	golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58
 	golang.org/x/sys v0.0.0-20201126233918-771906719818 // indirect
 	golang.org/x/tools v0.0.0-20201125231158-b5590deeca9b
diff --git a/go.sum b/go.sum
index 8122f7c4..09b1605d 100644
--- a/go.sum
+++ b/go.sum
@@ -153,6 +153,8 @@ github.com/go-openapi/loads v0.19.6 h1:6IAtnx22MNSjPocZZ2sV7EjgF6wW5rDC9r6ZkNxji
 github.com/go-openapi/loads v0.19.6/go.mod h1:brCsvE6j8mnbmGBh103PT/QLHfbyDxA4hsKvYBNEGVc=
 github.com/go-openapi/loads v0.19.7 h1:6cALLpCAq4tYhaic7TMbEzjv8vq/wg+0AFivNy/Bma8=
 github.com/go-openapi/loads v0.19.7/go.mod h1:brCsvE6j8mnbmGBh103PT/QLHfbyDxA4hsKvYBNEGVc=
+github.com/go-openapi/loads v0.20.0 h1:Pymw1O8zDmWeNv4kVsHd0W3cvgdp8juRa4U/U/8D/Pk=
+github.com/go-openapi/loads v0.20.0/go.mod h1:2LhKquiE513rN5xC6Aan6lYOSddlL8Mp20AW9kpviM4=
 github.com/go-openapi/runtime v0.0.0-20180920151709-4f900dc2ade9/go.mod h1:6v9a6LTXWQCdL8k1AO3cvqx5OtZY/Y9wKTgaoP6YRfA=
 github.com/go-openapi/runtime v0.19.0/go.mod h1:OwNfisksmmaZse4+gpV3Ne9AyMOlP1lt4sK4FXt0O64=
 github.com/go-openapi/runtime v0.19.4/go.mod h1:X277bwSUBxVlCYR3r7xgZZGKVvBd/29gLDlFGtJ8NL4=
@@ -168,6 +170,8 @@ github.com/go-openapi/spec v0.19.6/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHK
 github.com/go-openapi/spec v0.19.8/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk=
 github.com/go-openapi/spec v0.19.15 h1:uxh8miNJEfMm8l8ekpY7i39LcORm1xSRtoipEGl1JPk=
 github.com/go-openapi/spec v0.19.15/go.mod h1:+81FIL1JwC5P3/Iuuozq3pPE9dXdIEGxFutcFKaVbmU=
+github.com/go-openapi/spec v0.20.0 h1:HGLc8AJ7ynOxwv0Lq4TsnwLsWMawHAYiJIFzbcML86I=
+github.com/go-openapi/spec v0.20.0/go.mod h1:+81FIL1JwC5P3/Iuuozq3pPE9dXdIEGxFutcFKaVbmU=
 github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
 github.com/go-openapi/strfmt v0.18.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
 github.com/go-openapi/strfmt v0.19.0/go.mod h1:+uW+93UVvGGq2qGaZxdDeJqSAqBqBdl+ZPMF/cC8nDY=
@@ -199,6 +203,8 @@ github.com/go-openapi/validate v0.19.12 h1:mPLM/bfbd00PGOCJlU0yJL7IulkZ+q9VjPv7U
 github.com/go-openapi/validate v0.19.12/go.mod h1:Rzou8hA/CBw8donlS6WNEUQupNvUZ0waH08tGe6kAQ4=
 github.com/go-openapi/validate v0.19.15 h1:oUHZO8jD7p5oRLANlXF0U8ic9ePBUkDQyRZdN0EhL6M=
 github.com/go-openapi/validate v0.19.15/go.mod h1:tbn/fdOwYHgrhPBzidZfJC2MIVvs9GA7monOmWBbeCI=
+github.com/go-openapi/validate v0.20.0 h1:pzutNCCBZGZlE+u8HD3JZyWdc/TVbtVwlWUp8/vgUKk=
+github.com/go-openapi/validate v0.20.0/go.mod h1:b60iJT+xNNLfaQJUqLI7946tYiFEOuE9E4k54HpKcJ0=
 github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
@@ -478,6 +484,8 @@ go.mongodb.org/mongo-driver v1.3.4 h1:zs/dKNwX0gYUtzwrN9lLiR15hCO0nDwQj5xXx+vjCd
 go.mongodb.org/mongo-driver v1.3.4/go.mod h1:MSWZXKOynuguX+JSvwP8i+58jYCXxbia8HS3gZBapIE=
 go.mongodb.org/mongo-driver v1.4.3 h1:moga+uhicpVshTyaqY9L23E6QqwcHRUv1sqyOsoyOO8=
 go.mongodb.org/mongo-driver v1.4.3/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc=
+go.mongodb.org/mongo-driver v1.4.4 h1:bsPHfODES+/yx2PCWzUYMH8xj6PVniPI8DQrsJuSXSs=
+go.mongodb.org/mongo-driver v1.4.4/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc=
 go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
 go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
 go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
@@ -572,6 +580,8 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
 golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
 golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
 golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U=
+golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=


Test patch:
diff --git a/generator/build_test.go b/generator/build_test.go
index 768efa05..69ffaa52 100644
--- a/generator/build_test.go
+++ b/generator/build_test.go
@@ -1,16 +1,13 @@
 package generator_test
 
 import (
-	"bytes"
 	"io/ioutil"
 	"log"
 	"os"
 	"os/exec"
 	"path/filepath"
-	"strings"
 	"testing"
 
-	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 
 	"github.com/go-swagger/go-swagger/cmd/swagger/commands/generate"
@@ -24,6 +21,15 @@ const (
 )
 
 func TestGenerateAndBuild(t *testing.T) {
+	// This test generates and actually compiles the output
+	// of generated clients.
+	//
+	// We run this in parallel now. Therefore it is no more
+	// possible to assert the output on stdout.
+	//
+	// NOTE: test cases are randomized (map)
+	t.Parallel()
+
 	defer func() {
 		log.SetOutput(os.Stdout)
 	}()
@@ -54,33 +60,28 @@ func TestGenerateAndBuild(t *testing.T) {
 		},
 	}
 
-	for name, cas := range cases {
-		var captureLog bytes.Buffer
-		log.SetOutput(&captureLog)
-
-		t.Run(name, func(t *testing.T) {
-			spec := filepath.FromSlash(cas.spec)
+	t.Run("build client", func(t *testing.T) {
+		for name, cas := range cases {
+			t.Run(name, func(t *testing.T) {
+				t.Parallel()
+				log.SetOutput(ioutil.Discard)
 
-			generated, err := ioutil.TempDir(filepath.Dir(spec), "generated")
-			if err != nil {
-				t.Fatalf("TempDir()=%s", generated)
-			}
-			defer func() { _ = os.RemoveAll(generated) }()
+				spec := filepath.FromSlash(cas.spec)
 
-			err = newTestClient(spec, generated).Execute(nil)
-			require.NoErrorf(t, err, "Execute()=%s", err)
+				generated, err := ioutil.TempDir(filepath.Dir(spec), "generated")
+				require.NoErrorf(t, err, "TempDir()=%s", generated)
+				defer func() { _ = os.RemoveAll(generated) }()
 
-			assert.Contains(t, strings.ToLower(captureLog.String()), "generation completed")
+				require.NoErrorf(t, newTestClient(spec, generated).Execute(nil), "Execute()=%s", err)
 
-			packages := filepath.Join(generated, "...")
+				packages := filepath.Join(generated, "...")
 
-			p, err := exec.Command("go", "get", packages).CombinedOutput()
-			require.NoErrorf(t, err, "go get %s: %s\n%s", packages, err, p)
+				goExecInDir(t, "", "get")
 
-			p, err = exec.Command("go", "build", packages).CombinedOutput()
-			require.NoErrorf(t, err, "go build %s: %s\n%s", packages, err, p)
-		})
-	}
+				goExecInDir(t, "", "build", packages)
+			})
+		}
+	})
 }
 
 func newTestClient(input, output string) *generate.Client {
@@ -94,3 +95,10 @@ func newTestClient(input, output string) *generate.Client {
 	c.ClientPackage = defaultClientPackage
 	return c
 }
+
+func goExecInDir(t testing.TB, target string, args ...string) {
+	cmd := exec.Command("go", args...)
+	cmd.Dir = target
+	p, err := cmd.CombinedOutput()
+	require.NoErrorf(t, err, "unexpected error: %s: %v\n%s", cmd.String(), err, string(p))
+}
diff --git a/generator/client_test.go b/generator/client_test.go
index 2d697f48..a0327fa4 100644
--- a/generator/client_test.go
+++ b/generator/client_test.go
@@ -54,7 +54,8 @@ func testClientGenOpts() *GenOpts {
 }
 
 func Test_GenerateClient(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
+	t.Parallel()
+	defer discardOutput()()
 
 	// exercise safeguards
 	err := GenerateClient("test", []string{"model1"}, []string{"op1", "op2"}, nil)
@@ -147,7 +148,8 @@ func assertImports(t testing.TB, baseImport, code string) {
 }
 
 func TestClient(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
+	t.Parallel()
+	defer discardOutput()()
 
 	base := os.Getenv("GOPATH")
 	if base == "" {
@@ -273,45 +275,49 @@ func TestClient(t *testing.T) {
 		},
 	}
 
-	for i, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			opts := testClientGenOpts()
-			opts.Spec = basicFixture
-			opts.Target = filepath.Join(targetdir, opts.LanguageOpts.ManglePackageName(tt.name, "client_test"+strconv.Itoa(i)))
-			err := os.MkdirAll(opts.Target, 0755)
-			require.NoError(t, err)
-
-			if tt.spec == "" {
+	t.Run("generate client", func(t *testing.T) {
+		for idx, toPin := range tests {
+			tt := toPin
+			i := idx
+			t.Run(tt.name, func(t *testing.T) {
+				t.Parallel()
+				opts := testClientGenOpts()
 				opts.Spec = basicFixture
-			} else {
-				opts.Spec = tt.spec
-			}
-			opts.Template = tt.template
-
-			if tt.prepare != nil {
-				tt.prepare(opts)
-			}
-
-			err = GenerateClient("foo", nil, nil, opts)
-			if tt.wantError {
-				require.Errorf(t, err, "expected an error for client build fixture: %s", opts.Spec)
-			} else {
-				require.NoError(t, err, "unexpected error for client build fixture: %s", opts.Spec)
-			}
+				opts.Target = filepath.Join(targetdir, opts.LanguageOpts.ManglePackageName(tt.name, "client_test"+strconv.Itoa(i)))
+				err := os.MkdirAll(opts.Target, 0755)
+				require.NoError(t, err)
 
-			if tt.verify != nil {
-				tt.verify(t, opts.Target)
-			}
-		})
-	}
+				if tt.spec == "" {
+					opts.Spec = basicFixture
+				} else {
+					opts.Spec = tt.spec
+				}
+				opts.Template = tt.template
+
+				if tt.prepare != nil {
+					tt.prepare(opts)
+				}
+
+				err = GenerateClient("foo", nil, nil, opts)
+				if tt.wantError {
+					require.Errorf(t, err, "expected an error for client build fixture: %s", opts.Spec)
+				} else {
+					require.NoError(t, err, "unexpected error for client build fixture: %s", opts.Spec)
+				}
+
+				if tt.verify != nil {
+					tt.verify(t, opts.Target)
+				}
+			})
+		}
+	})
 }
 
 func TestGenClient_1518(t *testing.T) {
+	t.Parallel()
+	defer discardOutput()()
+
 	// test client response handling when unexpected success response kicks in
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
 
 	opts := testClientGenOpts()
 	opts.Spec = filepath.Join("..", "fixtures", "bugs", "1518", "fixture-1518.yaml")
@@ -321,13 +327,11 @@ func TestGenClient_1518(t *testing.T) {
 	opts.Target = tft
 
 	defer func() {
-		_ = os.RemoveAll(opts.Target)
+		_ = os.RemoveAll(tft)
 	}()
 
 	err := GenerateClient("client", []string{}, []string{}, opts)
-	if !assert.NoError(t, err) {
-		t.FailNow()
-	}
+	require.NoError(t, err)
 
 	fixtureConfig := map[string][]string{
 		"client/operations/operations_client.go": { // generated file
@@ -365,6 +369,7 @@ func TestGenClient_1518(t *testing.T) {
 	for fileToInspect, expectedCode := range fixtureConfig {
 		code, err := ioutil.ReadFile(filepath.Join(opts.Target, filepath.FromSlash(fileToInspect)))
 		require.NoError(t, err)
+
 		for line, codeLine := range expectedCode {
 			if !assertInCode(t, strings.TrimSpace(codeLine), string(code)) {
 				t.Logf("Code expected did not match in codegenfile %s for expected line %d: %q", fileToInspect, line, expectedCode[line])
diff --git a/generator/discriminators_test.go b/generator/discriminators_test.go
index 5ecdb323..a474c103 100644
--- a/generator/discriminators_test.go
+++ b/generator/discriminators_test.go
@@ -34,7 +34,7 @@ func TestGenerateModel_DiscriminatorSlices(t *testing.T) {
 	assert.True(t, genModel.HasBaseType)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("model").Execute(buf, genModel)
+	err = opts.templates.MustGet("model").Execute(buf, genModel)
 	require.NoError(t, err)
 
 	b, err := opts.LanguageOpts.FormatContent("has_discriminator.go", buf.Bytes())
@@ -65,7 +65,7 @@ func TestGenerateModel_Discriminators(t *testing.T) {
 		assert.Equal(t, k, genModel.DiscriminatorValue)
 
 		buf := bytes.NewBuffer(nil)
-		err = templates.MustGet("model").Execute(buf, genModel)
+		err = opts.templates.MustGet("model").Execute(buf, genModel)
 		require.NoError(t, err)
 
 		b, err := opts.LanguageOpts.FormatContent("discriminated.go", buf.Bytes())
@@ -117,7 +117,7 @@ func TestGenerateModel_Discriminators(t *testing.T) {
 	assert.Equal(t, "Dog", genModel.Discriminates["Dog"])
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("model").Execute(buf, genModel)
+	err = opts.templates.MustGet("model").Execute(buf, genModel)
 	require.NoError(t, err)
 
 	b, err := opts.LanguageOpts.FormatContent("with_discriminator.go", buf.Bytes())
@@ -154,7 +154,7 @@ func TestGenerateModel_UsesDiscriminator(t *testing.T) {
 	require.True(t, genModel.HasBaseType)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("model").Execute(buf, genModel)
+	err = opts.templates.MustGet("model").Execute(buf, genModel)
 	require.NoError(t, err)
 
 	b, err := opts.LanguageOpts.FormatContent("has_discriminator.go", buf.Bytes())
@@ -174,6 +174,7 @@ func TestGenerateClient_OKResponseWithDiscriminator(t *testing.T) {
 	method, path, op, ok := analysis.New(specDoc.Spec()).OperationForName("modelOp")
 	require.True(t, ok)
 
+	opts := opts()
 	bldr := codeGenOpBuilder{
 		Name:          "modelOp",
 		Method:        method,
@@ -188,7 +189,7 @@ func TestGenerateClient_OKResponseWithDiscriminator(t *testing.T) {
 		Authed:        false,
 		DefaultScheme: "http",
 		ExtraSchemas:  make(map[string]GenSchema),
-		GenOpts:       opts(),
+		GenOpts:       opts,
 	}
 
 	genOp, err := bldr.MakeOperation()
@@ -196,7 +197,7 @@ func TestGenerateClient_OKResponseWithDiscriminator(t *testing.T) {
 
 	assert.True(t, genOp.Responses[0].Schema.IsBaseType)
 	var buf bytes.Buffer
-	err = templates.MustGet("clientResponse").Execute(&buf, genOp)
+	err = opts.templates.MustGet("clientResponse").Execute(&buf, genOp)
 	require.NoError(t, err)
 
 	res := buf.String()
@@ -212,6 +213,7 @@ func TestGenerateServer_Parameters(t *testing.T) {
 	method, path, op, ok := analysis.New(specDoc.Spec()).OperationForName("modelOp")
 	require.True(t, ok)
 
+	opts := opts()
 	bldr := codeGenOpBuilder{
 		Name:          "modelOp",
 		Method:        method,
@@ -226,14 +228,14 @@ func TestGenerateServer_Parameters(t *testing.T) {
 		Authed:        false,
 		DefaultScheme: "http",
 		ExtraSchemas:  make(map[string]GenSchema),
-		GenOpts:       opts(),
+		GenOpts:       opts,
 	}
 	genOp, err := bldr.MakeOperation()
 	require.NoError(t, err)
 
 	assert.True(t, genOp.Responses[0].Schema.IsBaseType)
 	var buf bytes.Buffer
-	err = templates.MustGet("serverParameter").Execute(&buf, genOp)
+	err = opts.templates.MustGet("serverParameter").Execute(&buf, genOp)
 	require.NoErrorf(t, err, buf.String())
 
 	res := buf.String()
@@ -255,7 +257,7 @@ func TestGenerateModel_Discriminator_Billforward(t *testing.T) {
 	require.True(t, genModel.IsSubType)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("model").Execute(buf, genModel)
+	err = opts.templates.MustGet("model").Execute(buf, genModel)
 	require.NoError(t, err)
 
 	b, err := opts.LanguageOpts.FormatContent("has_discriminator.go", buf.Bytes())
@@ -286,7 +288,7 @@ func TestGenerateModel_Bitbucket_Repository(t *testing.T) {
 	}
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("model").Execute(buf, genModel)
+	err = opts.templates.MustGet("model").Execute(buf, genModel)
 	require.NoError(t, err)
 
 	b, err := opts.LanguageOpts.FormatContent("repository.go", buf.Bytes())
@@ -309,7 +311,7 @@ func TestGenerateModel_Bitbucket_WebhookSubscription(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("model").Execute(buf, genModel)
+	err = opts.templates.MustGet("model").Execute(buf, genModel)
 	require.NoError(t, err)
 
 	b, err := opts.LanguageOpts.FormatContent("webhook_subscription.go", buf.Bytes())
@@ -333,7 +335,7 @@ func TestGenerateModel_Issue319(t *testing.T) {
 	require.Equal(t, "map[string]Base", genModel.Properties[0].GoType)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("model").Execute(buf, genModel)
+	err = opts.templates.MustGet("model").Execute(buf, genModel)
 	require.NoError(t, err)
 
 	b, err := opts.LanguageOpts.FormatContent("ifacedmap.go", buf.Bytes())
@@ -356,7 +358,7 @@ func TestGenerateModel_Issue541(t *testing.T) {
 	require.NotEmpty(t, genModel.AllOf)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("model").Execute(buf, genModel)
+	err = opts.templates.MustGet("model").Execute(buf, genModel)
 	require.NoError(t, err)
 
 	b, err := opts.LanguageOpts.FormatContent("lion.go", buf.Bytes())
@@ -380,7 +382,7 @@ func TestGenerateModel_Issue436(t *testing.T) {
 	require.NotEmpty(t, genModel.AllOf)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("model").Execute(buf, genModel)
+	err = opts.templates.MustGet("model").Execute(buf, genModel)
 	require.NoError(t, err)
 
 	b, err := opts.LanguageOpts.FormatContent("lion.go", buf.Bytes())
@@ -407,7 +409,7 @@ func TestGenerateModel_Issue740(t *testing.T) {
 	require.NotEmpty(t, genModel.AllOf)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("model").Execute(buf, genModel)
+	err = opts.templates.MustGet("model").Execute(buf, genModel)
 	require.NoError(t, err)
 
 	b, err := opts.LanguageOpts.FormatContent("bar.go", buf.Bytes())
@@ -431,7 +433,7 @@ func TestGenerateModel_Issue743(t *testing.T) {
 	require.NotEmpty(t, genModel.AllOf)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("model").Execute(buf, genModel)
+	err = opts.templates.MustGet("model").Execute(buf, genModel)
 	require.NoError(t, err)
 
 	b, err := opts.LanguageOpts.FormatContent("awol.go", buf.Bytes())
diff --git a/generator/enum_test.go b/generator/enum_test.go
index b8105f1b..055cbe3c 100644
--- a/generator/enum_test.go
+++ b/generator/enum_test.go
@@ -443,21 +443,22 @@ func TestGenerateModel_Issue303(t *testing.T) {
 		assert.Equal(t, name, genModel.Name)
 		assert.Equal(t, name, genModel.GoType)
 		assert.True(t, genModel.IsEnumCI)
+
 		extension := genModel.Extensions["x-go-enum-ci"]
-		assert.NotNil(t, extension)
+		require.NotNil(t, extension)
+
 		xGoEnumCI, ok := extension.(bool)
 		assert.True(t, ok)
 		assert.True(t, xGoEnumCI)
 
 		buf := bytes.NewBuffer(nil)
-		err = tt.template.Execute(buf, genModel)
-		require.NoError(t, err)
+		require.NoError(t, tt.template.Execute(buf, genModel))
 
 		ff, err := opts.LanguageOpts.FormatContent("case_insensitive_enum_definition.go", buf.Bytes())
 		require.NoErrorf(t, err, buf.String())
 
 		res := string(ff)
-		assertInCode(t, `		if err := validate.EnumCase(path, location, value, vegetableEnum, false); err != nil {`, res)
+		assertInCode(t, `if err := validate.EnumCase(path, location, value, vegetableEnum, false); err != nil {`, res)
 	}
 }
 
diff --git a/generator/generate_test.go b/generator/generate_test.go
index 3260395b..cf48d26f 100644
--- a/generator/generate_test.go
+++ b/generator/generate_test.go
@@ -2,71 +2,145 @@ package generator
 
 import (
 	"bytes"
-	"fmt"
 	"io/ioutil"
 	"log"
 	"os"
-	"os/exec"
+	"path"
 	"path/filepath"
 	"runtime"
+	"strings"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 )
 
+func TestGenerateAndTest(t *testing.T) {
+	defer discardOutput()()
+
+	cwd := testCwd(t)
+	const root = "generated"
+	defer func() {
+		_ = os.RemoveAll(filepath.Join(cwd, root))
+	}()
+
+	t.Run("server build", func(t *testing.T) {
+		for name, cas := range generateFixtures(t) {
+			thisCas := cas
+			thisName := name
+
+			t.Run(thisName, func(t *testing.T) {
+				t.Parallel()
+
+				log.SetOutput(ioutil.Discard)
+				defer thisCas.warnFailed(t)
+
+				// default opts
+				opts := testGenOpts()
+
+				// create directory layout, defer clean
+				defer thisCas.prepareTarget(t, thisName, "server_test", root, opts)()
+
+				// preparation before generation
+				if thisCas.prepare != nil {
+					thisCas.prepare(t, opts)
+				}
+
+				t.Logf("generating test server at: %s, from %s", opts.Target, opts.Spec)
+
+				err := GenerateServer("", nil, nil, opts)
+				if thisCas.wantError {
+					require.Errorf(t, err, "expected an error for server build fixture: %s", opts.Spec)
+				} else {
+					require.NoError(t, err, "unexpected error for server build fixture: %s", opts.Spec)
+				}
+
+				// verify
+				if thisCas.verify != nil {
+					thisCas.verify(t, opts.Target)
+				}
+
+				// fixture-specific clean
+				if thisCas.clean != nil {
+					thisCas.clean()
+				}
+			})
+		}
+	})
+}
+
 type generateFixture struct {
-	name   string
-	spec   string
-	target string
-	//template  string
+	name      string
+	spec      string
+	target    string
 	wantError bool
-	prepare   func(opts *GenOpts)
+	prepare   func(testing.TB, *GenOpts)
 	verify    func(testing.TB, string)
 	clean     func()
 }
 
-func (f generateFixture) prepareTarget(name, base string, opts *GenOpts) func() {
+func (f generateFixture) base(t testing.TB, root string) (string, func()) {
+	// base generation target
+	cwd := testCwd(t)
+
+	base := filepath.Join(cwd, root)
+	require.NoErrorf(t, os.MkdirAll(base, 0700), "error in test creating target dir")
+
+	generated, err := ioutil.TempDir(base, "generated")
+	require.NoErrorf(t, err, "error in test creating temp dir")
+
+	return generated, func() {
+		_ = os.RemoveAll(generated)
+	}
+}
+
+func (f generateFixture) prepareTarget(t testing.TB, name, base, root string, opts *GenOpts) func() {
 	if name == "" {
 		name = f.name
 	}
+
 	spec := filepath.FromSlash(f.spec)
+	opts.Spec = spec
+
+	generated, clean := f.base(t, root)
+
 	if f.target == "" {
-		opts.Target = filepath.Join(filepath.Dir(spec), opts.LanguageOpts.ManglePackageName(name, base))
+		opts.Target = filepath.Join(generated, opts.LanguageOpts.ManglePackageName(name, base))
 	} else {
-		opts.Target = f.target
-	}
-	opts.Spec = spec
-	_ = os.MkdirAll(opts.Target, 0700)
-	return func() {
-		if f.target == "" {
-			_ = os.RemoveAll(filepath.Join(opts.Target))
-			return
-		}
-		_ = os.RemoveAll(filepath.Join(f.target, defaultServerTarget))
-		_ = os.RemoveAll(filepath.Join(f.target, "cmd"))
-		_ = os.RemoveAll(filepath.Join(f.target, defaultModelsTarget))
+		opts.Target = filepath.Join(generated, filepath.Base(f.target))
 	}
+
+	require.NoErrorf(t, os.MkdirAll(opts.Target, 0700), "error in test creating target dir")
+
+	return clean
 }
 
-func (f generateFixture) warnFailed(t testing.TB, buf fmt.Stringer) func() {
+func (f generateFixture) warnFailed(t testing.TB) func() {
 	return func() {
 		if t.Failed() {
-			t.Logf("ERROR: generation failed:\n%s", buf.String())
+			t.Log("ERROR: generation failed")
 		}
 	}
 }
 
-func TestGenerateAndTest(t *testing.T) {
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
-
-	cases := map[string]generateFixture{
+func generateFixtures(t testing.TB) map[string]generateFixture {
+	return map[string]generateFixture{
 		"issue 1943": {
 			spec:   "../fixtures/bugs/1943/fixture-1943.yaml",
 			target: "../fixtures/bugs/1943",
-			prepare: func(opts *GenOpts) {
+			prepare: func(_ testing.TB, opts *GenOpts) {
+				input, err := ioutil.ReadFile("../fixtures/bugs/1943/datarace_test.go")
+				require.NoError(t, err)
+
+				// rewrite imports for the relocated test program
+				cwd := testCwd(t)
+				rebased := bytes.ReplaceAll(
+					input,
+					[]byte("/fixtures/bugs/1943"),
+					[]byte(filepath.ToSlash(strings.TrimPrefix(opts.Target, filepath.Dir(cwd)))),
+				)
+
+				require.NoError(t, ioutil.WriteFile(filepath.Join(opts.Target, "datarace_test.go"), rebased, 0600))
 				opts.ExcludeSpec = false
 			},
 			verify: func(t testing.TB, target string) {
@@ -75,69 +149,67 @@ func TestGenerateAndTest(t *testing.T) {
 					t.Logf("warn: race test skipped on windows")
 					return
 				}
-				packages := filepath.Join(target, "...")
-				testPrg := filepath.Join(target, "datarace_test.go")
 
-				if p, err := exec.Command("go", "get", packages).CombinedOutput(); err != nil {
-					if !assert.NoError(t, err, "go get %s: %s\n%s", packages, err, p) {
-						return
-					}
-				}
+				const packages = "./..."
+				testPrg := "datarace_test.go"
 
-				t.Log("running data race test on generated server")
-				if p, err := exec.Command("go", "test", "-v", "-race", testPrg).CombinedOutput(); err != nil {
-					if !assert.NoError(t, err, "go test -race %s: %s\n%s", packages, err, p) {
-						return
-					}
-				}
+				goExecInDir(t, target, "get", packages)
 
+				t.Log("running data race test on generated server")
+				goExecInDir(t, target, "test", "-v", "-race", testPrg)
 			},
 		},
 		"packages_mangling": {
 			spec: "../fixtures/bugs/2111/fixture-2111.yaml",
-			prepare: func(opts *GenOpts) {
+			prepare: func(_ testing.TB, opts *GenOpts) {
 				opts.IncludeMain = true
 			},
 			verify: func(t testing.TB, target string) {
 				require.True(t, fileExists(target, defaultServerTarget))
 				assert.True(t, fileExists(filepath.Join(target, "cmd", "unsafe-tag-names-server"), "main.go"))
 
-				target = filepath.Join(target, defaultServerTarget)
+				srvTarget := filepath.Join(target, defaultServerTarget)
+				opsTarget := filepath.Join(srvTarget, defaultOperationsTarget)
+				require.True(t, fileExists(opsTarget, ""))
+
+				for _, fileOrDir := range []string{
+					"abc_linux", "abc_test",
+					"api",
+					"custom",
+					"hash_tag_donuts",
+					"nr123abc", "nr_at_donuts", "plus_donuts",
+					"strfmt",
+					"forced",
+					"gtl",
+					"nr12nasty",
+					"override",
+					"get_notag.go",
+					"operationsops",
+				} {
+					assert.True(t, fileExists(opsTarget, fileOrDir))
+				}
 
-				buf, err := ioutil.ReadFile(filepath.Join(target, "configure_unsafe_tag_names.go"))
+				buf, err := ioutil.ReadFile(filepath.Join(srvTarget, "configure_unsafe_tag_names.go"))
 				require.NoError(t, err)
 
-				target = filepath.Join(target, defaultOperationsTarget)
-				require.True(t, fileExists(target, ""))
-
-				assert.True(t, fileExists(target, "abc_linux"))
-				assert.True(t, fileExists(target, "abc_test"))
-				assert.True(t, fileExists(target, "api"))
-				assert.True(t, fileExists(target, "custom"))
-				assert.True(t, fileExists(target, "hash_tag_donuts"))
-				assert.True(t, fileExists(target, "nr123abc"))
-				assert.True(t, fileExists(target, "nr_at_donuts"))
-				assert.True(t, fileExists(target, "plus_donuts"))
-				assert.True(t, fileExists(target, "strfmt"))
-				assert.True(t, fileExists(target, "forced"))
-				assert.True(t, fileExists(target, "gtl"))
-				assert.True(t, fileExists(target, "nr12nasty"))
-				assert.True(t, fileExists(target, "override"))
-				assert.True(t, fileExists(target, "get_notag.go"))
-				assert.True(t, fileExists(target, "operationsops"))
-
-				buf2, err := ioutil.ReadFile(filepath.Join(target, "unsafe_tag_names_api.go"))
-				require.NoError(t, err)
+				code := string(buf)
 
 				// assert imports, with deconfliction
-				code := string(buf)
-				baseImport := `github.com/go-swagger/go-swagger/fixtures/bugs/2111/packages_mangling/restapi/operations`
+				cwd := testCwd(t)
+				base := path.Join("github.com", "go-swagger", "go-swagger",
+					filepath.ToSlash(strings.TrimPrefix(target, filepath.Dir(cwd))),
+				)
+
+				baseImport := path.Join(base, `restapi/operations`)
 				assertImports(t, baseImport, code)
 
 				assertInCode(t, `api.APIGetConflictHandler = apiops.GetConflictHandlerFunc(`, code)
 				assertInCode(t, `api.StrfmtGetAnotherConflictHandler = strfmtops.GetAnotherConflictHandlerFunc(`, code)
 				assertInCode(t, `api.GetNotagHandler = operations.GetNotagHandlerFunc(`, code)
 
+				buf2, err := ioutil.ReadFile(filepath.Join(opsTarget, "unsafe_tag_names_api.go"))
+				require.NoError(t, err)
+
 				api := string(buf2)
 				assertImports(t, baseImport, api)
 
@@ -164,48 +236,54 @@ func TestGenerateAndTest(t *testing.T) {
 		},
 		"packages_flattening": {
 			spec: "../fixtures/bugs/2111/fixture-2111.yaml",
-			prepare: func(opts *GenOpts) {
+			prepare: func(_ testing.TB, opts *GenOpts) {
 				opts.SkipTagPackages = true
 			},
 			verify: func(t testing.TB, target string) {
 				require.True(t, fileExists(target, defaultServerTarget))
 
-				target = filepath.Join(target, defaultServerTarget)
-				buf, err := ioutil.ReadFile(filepath.Join(target, "configure_unsafe_tag_names.go"))
-				require.NoError(t, err)
+				srvTarget := filepath.Join(target, defaultServerTarget)
+				opsTarget := filepath.Join(srvTarget, defaultOperationsTarget)
+				require.True(t, fileExists(opsTarget, ""))
+
+				for _, fileOrDir := range []string{
+					"abc_linux", "abc_test",
+					"api",
+					"custom",
+					"hash_tag_donuts",
+					"nr123abc", "nr_at_donuts", "plus_donuts",
+					"strfmt",
+					"forced",
+					"gtl",
+					"nr12nasty",
+					"override",
+					"operationsops",
+				} {
+					assert.Falsef(t, fileExists(opsTarget, fileOrDir), "did not expect %s in %s", fileOrDir, opsTarget)
+				}
 
-				target = filepath.Join(target, defaultOperationsTarget)
-				require.True(t, fileExists(target, ""))
-
-				assert.False(t, fileExists(target, "abc_linux"))
-				assert.False(t, fileExists(target, "abc_test"))
-				assert.False(t, fileExists(target, "api"))
-				assert.False(t, fileExists(target, "custom"))
-				assert.False(t, fileExists(target, "hash_tag_donuts"))
-				assert.False(t, fileExists(target, "nr123abc"))
-				assert.False(t, fileExists(target, "nr_at_donuts"))
-				assert.False(t, fileExists(target, "plus_donuts"))
-				assert.False(t, fileExists(target, "strfmt"))
-				assert.False(t, fileExists(target, "forced"))
-				assert.False(t, fileExists(target, "gtl"))
-				assert.False(t, fileExists(target, "nr12nasty"))
-				assert.False(t, fileExists(target, "override"))
-				assert.False(t, fileExists(target, "operationsops"))
-
-				assert.True(t, fileExists(target, "get_notag.go"))
-
-				buf2, err := ioutil.ReadFile(filepath.Join(target, "unsafe_tag_names_api.go"))
-				require.NoError(t, err)
+				assert.Truef(t, fileExists(opsTarget, "get_notag.go"), "expected %s in %s", "get_notag.go", opsTarget)
 
+				buf, err := ioutil.ReadFile(filepath.Join(srvTarget, "configure_unsafe_tag_names.go"))
+				require.NoError(t, err)
 				code := string(buf)
-				baseImport := `github.com/go-swagger/go-swagger/fixtures/bugs/2111/packages_flattening/restapi/operations`
+
+				cwd := testCwd(t)
+				base := path.Join("github.com", "go-swagger", "go-swagger",
+					filepath.ToSlash(strings.TrimPrefix(target, filepath.Dir(cwd))),
+				)
+
+				baseImport := path.Join(base, `restapi/operations`)
 				assertRegexpInCode(t, baseImport, code)
 
 				assertInCode(t, `api.GetConflictHandler = operations.GetConflictHandlerFunc(`, code)
 				assertInCode(t, `api.GetAnotherConflictHandler = operations.GetAnotherConflictHandlerFunc(`, code)
 				assertInCode(t, `api.GetNotagHandler = operations.GetNotagHandlerFunc(`, code)
 
+				buf2, err := ioutil.ReadFile(filepath.Join(opsTarget, "unsafe_tag_names_api.go"))
+				require.NoError(t, err)
 				api := string(buf2)
+
 				assertInCode(t, `GetConflictHandler: GetConflictHandlerFunc(func(params GetConflictParams) middleware.Responder {`, api)
 				assertInCode(t, `GetAnotherConflictHandler: GetAnotherConflictHandlerFunc(func(params GetAnotherConflictParams) middleware.Responder {`, api)
 				assertInCode(t, `NotagHandler: GetNotagHandlerFunc(func(params GetNotagParams) middleware.Responder {`, api)
@@ -229,7 +307,7 @@ func TestGenerateAndTest(t *testing.T) {
 		},
 		"main_package": {
 			spec: "../fixtures/bugs/2111/fixture-2111.yaml",
-			prepare: func(opts *GenOpts) {
+			prepare: func(_ testing.TB, opts *GenOpts) {
 				opts.IncludeMain = true
 				opts.MainPackage = "custom-api"
 				opts.SkipTagPackages = true
@@ -239,307 +317,185 @@ func TestGenerateAndTest(t *testing.T) {
 			},
 		},
 		"external_model": {
-			spec:   "../fixtures/bugs/1897/fixture-1897.yaml",
-			target: "../fixtures/bugs/1897/codegen",
-			prepare: func(opts *GenOpts) {
-				modelOpts := testGenOpts()
+			spec: "../fixtures/bugs/1897/fixture-1897.yaml",
+			prepare: func(t testing.TB, opts *GenOpts) {
+				modelOpts := *opts
 				modelOpts.AcceptDefinitionsOnly = true
 				modelOpts.Spec = "../fixtures/bugs/1897/model.yaml"
-				modelOpts.Target = "../fixtures/bugs/1897"
 				modelOpts.ModelPackage = "external"
-				err := GenerateModels(nil, modelOpts)
-				require.NoError(t, err)
+				modelOpts.Target = filepath.Dir(modelOpts.Spec)
+
+				require.NoError(t, GenerateModels(nil, &modelOpts))
+
 				t.Logf("generated external model")
+				require.True(t, fileExists(modelOpts.Target, filepath.Join("external")))
+				require.True(t, fileExists(modelOpts.Target, filepath.Join("external", "error.go")))
+
 				opts.IncludeMain = true
 			},
 			verify: func(t testing.TB, target string) {
-				defer func() {
-					_ = os.RemoveAll(target)
-				}()
-				require.True(t, fileExists(target, filepath.Join("..", "external")))
-				defer func() {
-					_ = os.RemoveAll(filepath.Join(target, "..", "external"))
-				}()
-
-				require.True(t, fileExists(target, filepath.Join("..", "external", "error.go")))
-				require.True(t, fileExists(target, filepath.Join("cmd", "repro1897-server")))
-
-				cwd, err := os.Getwd()
-				require.NoError(t, err)
-
-				err = os.Chdir(filepath.Join(target, "cmd", "repro1897-server"))
-				require.NoError(t, err)
-				defer func() {
-					_ = os.Chdir(cwd)
-				}()
+				location := filepath.Join(target, "cmd", "repro1897-server")
+				require.True(t, fileExists("", location))
 
 				t.Log("building generated server")
-				p, err := exec.Command("go", "build").CombinedOutput()
-				require.NoErrorf(t, err, string(p))
+				goExecInDir(t, location, "build")
+			},
+			clean: func() {
+				// remove generated external models
+				_ = os.RemoveAll(filepath.Join("..", "fixtures", "bugs", "1897", "external"))
 			},
 		},
 		"external_models_hints": {
 			spec:   "../fixtures/enhancements/2224/fixture-2224.yaml",
-			target: "../fixtures/enhancements/2224/codegen",
-			prepare: func(opts *GenOpts) {
-				modelOpts := testGenOpts()
+			target: "2224-hints",
+			prepare: func(t testing.TB, opts *GenOpts) {
+				modelOpts := *opts
 				modelOpts.AcceptDefinitionsOnly = true
 				modelOpts.Spec = "../fixtures/enhancements/2224/fixture-2224-models.yaml"
-				modelOpts.Target = "../fixtures/enhancements/2224"
 				modelOpts.ModelPackage = "external"
-				err := GenerateModels(nil, modelOpts)
-				require.NoError(t, err)
+				modelOpts.Target = filepath.Dir(modelOpts.Spec)
+
+				require.NoError(t, GenerateModels(nil, &modelOpts))
+
 				t.Logf("generated external model")
-				opts.IncludeMain = true
-			},
-			verify: func(t testing.TB, target string) {
-				defer func() {
-					_ = os.RemoveAll(target)
-				}()
-				require.True(t, fileExists(target, filepath.Join("..", "external")))
-				defer func() {
-					_ = os.RemoveAll(filepath.Join(target, "..", "external"))
-				}()
+				require.True(t, fileExists(modelOpts.Target, filepath.Join("external")))
 
 				for _, model := range []string{
-					"access_point.go",
-					"base.go",
-					"hotspot.go",
-					"hotspot_type.go",
-					"incorrect.go",
-					"json_message.go",
-					"json_object.go",
-					"json_object_with_alias.go",
-					"object_with_embedded.go",
-					"object_with_externals.go",
-					"raw.go",
-					"request.go",
-					"request_pointer.go",
-					"time_as_object.go",
-					"time.go",
+					"access_point.go", "base.go",
+					"hotspot.go", "hotspot_type.go",
+					"incorrect.go", "json_message.go",
+					"json_object.go", "json_object_with_alias.go",
+					"object_with_embedded.go", "object_with_externals.go",
+					"raw.go", "request.go",
+					"request_pointer.go", "time_as_object.go", "time.go",
 				} {
-					require.True(t, fileExists(target, filepath.Join("..", "external", model)))
+					require.True(t, fileExists(modelOpts.Target, filepath.Join("external", model)))
 				}
+
+				opts.IncludeMain = true
+			},
+			verify: func(t testing.TB, target string) {
+				// generated models (not external)
 				require.True(t, fileExists(target, filepath.Join("models")))
 				for _, model := range []string{"error.go", "external_with_embed.go"} {
 					require.True(t, fileExists(target, filepath.Join("models", model)))
 				}
-				require.True(t, fileExists(target, filepath.Join("cmd", "external-types-with-hints-server")))
 
-				cwd, err := os.Getwd()
-				require.NoError(t, err)
-
-				err = os.Chdir(filepath.Join(target, "cmd", "external-types-with-hints-server"))
-				require.NoError(t, err)
-				defer func() {
-					_ = os.Chdir(cwd)
-				}()
+				location := filepath.Join(target, "cmd", "external-types-with-hints-server")
+				require.True(t, fileExists("", location))
 
 				t.Log("building generated server")
-				p, err := exec.Command("go", "build").CombinedOutput()
-				require.NoErrorf(t, err, string(p))
+				goExecInDir(t, location, "build")
+			},
+			clean: func() {
+				// remove generated external models
+				_ = os.RemoveAll(filepath.Join("..", "fixtures", "enhancements", "2224", "external"))
 			},
 		},
 		"conflict_name_api_issue_2405_1": {
 			spec:   "../examples/todo-list/swagger.yml",
-			target: "codegen/2405-1",
-			prepare: func(opts *GenOpts) {
-				opts.Target = "codegen/2405-1"
+			target: "2405-1",
+			prepare: func(_ testing.TB, opts *GenOpts) {
 				opts.ServerPackage = "api"
 				opts.IncludeMain = true
 			},
 			verify: func(t testing.TB, target string) {
-				cwd, err := os.Getwd()
-				require.NoError(t, err)
-
-				require.True(t, fileExists(target, filepath.Join("cmd", "simple-to-do-list-api-server")))
-
-				err = os.Chdir(filepath.Join(target, "cmd", "simple-to-do-list-api-server"))
-				require.NoError(t, err)
-				defer func() {
-					_ = os.Chdir(cwd)
-				}()
+				location := filepath.Join(target, "cmd", "simple-to-do-list-api-server")
+				require.True(t, fileExists("", location))
 
 				t.Log("building generated server")
-				p, err := exec.Command("go", "build").CombinedOutput()
-				require.NoErrorf(t, err, string(p))
-			},
-			clean: func() {
-				_ = os.RemoveAll("codegen")
+				goExecInDir(t, location, "build")
 			},
 		},
 		"conflict_name_api_issue_2405_2": {
 			spec:   "../examples/todo-list/swagger.yml",
-			target: "codegen/2405-2",
-			prepare: func(opts *GenOpts) {
-				opts.Target = "codegen/2405-2"
+			target: "2405-2",
+			prepare: func(_ testing.TB, opts *GenOpts) {
 				opts.ServerPackage = "loads"
 				opts.IncludeMain = true
 			},
 			verify: func(t testing.TB, target string) {
-				cwd, err := os.Getwd()
-				require.NoError(t, err)
-
-				require.True(t, fileExists(target, filepath.Join("cmd", "simple-to-do-list-api-server")))
-
-				err = os.Chdir(filepath.Join(target, "cmd", "simple-to-do-list-api-server"))
-				require.NoError(t, err)
-				defer func() {
-					_ = os.Chdir(cwd)
-				}()
+				location := filepath.Join(target, "cmd", "simple-to-do-list-api-server")
+				require.True(t, fileExists("", location))
 
 				t.Log("building generated server")
-				p, err := exec.Command("go", "build").CombinedOutput()
-				require.NoErrorf(t, err, string(p))
-			},
-			clean: func() {
-				_ = os.RemoveAll("codegen")
+				goExecInDir(t, location, "build")
 			},
 		},
 		"conflict_name_api_issue_2405_3": {
 			spec:   "../fixtures/bugs/2405/fixture-2405.yaml",
-			target: "codegen/2405-3",
-			prepare: func(opts *GenOpts) {
-				opts.Target = "codegen/2405-3"
+			target: "2405-3",
+			prepare: func(_ testing.TB, opts *GenOpts) {
 				opts.ServerPackage = "server"
 				opts.APIPackage = "api"
 				opts.IncludeMain = true
 			},
 			verify: func(t testing.TB, target string) {
-				cwd, err := os.Getwd()
-				require.NoError(t, err)
-
-				require.True(t, fileExists(target, filepath.Join("cmd", "simple-to-do-list-api-server")))
-
-				err = os.Chdir(filepath.Join(target, "cmd", "simple-to-do-list-api-server"))
-				require.NoError(t, err)
-				defer func() {
-					_ = os.Chdir(cwd)
-				}()
+				location := filepath.Join(target, "cmd", "simple-to-do-list-api-server")
+				require.True(t, fileExists("", location))
 
 				t.Log("building generated server")
-				p, err := exec.Command("go", "build").CombinedOutput()
-				require.NoErrorf(t, err, string(p))
-			},
-			clean: func() {
-				_ = os.RemoveAll("codegen")
+				goExecInDir(t, location, "build")
 			},
 		},
 		"ext_types_issue_2385": {
 			spec:   "../fixtures/bugs/2385/fixture-2385.yaml",
-			target: "codegen/2385",
-			prepare: func(opts *GenOpts) {
-				opts.Target = "codegen/2385"
+			target: "2385",
+			prepare: func(t testing.TB, opts *GenOpts) {
 				opts.MainPackage = "nrcodegen-server"
 				opts.IncludeMain = true
 				location := filepath.Join(opts.Target, "models")
+
+				// add some custom model to the generated models
 				addModelsToLocation(t, location, "my_type.go")
 			},
-			verify: func(t testing.TB, target string) {
-				cwd, err := os.Getwd()
-				require.NoError(t, err)
-
-				require.True(t, fileExists(target, filepath.Join("cmd", "nrcodegen-server")))
-
-				err = os.Chdir(filepath.Join(target, "cmd", "nrcodegen-server"))
-				require.NoError(t, err)
-				defer func() {
-					_ = os.Chdir(cwd)
-				}()
+			verify: func(_ testing.TB, target string) {
+				location := filepath.Join(target, "cmd", "nrcodegen-server")
+				require.True(t, fileExists("", location))
 
 				t.Log("building generated server")
-				p, err := exec.Command("go", "build").CombinedOutput()
-				require.NoErrorf(t, err, string(p))
+				goExecInDir(t, location, "build")
 
-				err = os.Chdir(filepath.Join(cwd, target, "models"))
-				require.NoError(t, err)
+				location = filepath.Join(target, "models")
 
 				t.Log("building generated models")
-				p, err = exec.Command("go", "build").CombinedOutput()
-				require.NoErrorf(t, err, string(p))
-			},
-			clean: func() {
-				_ = os.RemoveAll("codegen")
+				goExecInDir(t, location, "build")
 			},
 		},
 		"ext_types_full_example": {
 			spec:   "../examples/external-types/example-external-types.yaml",
-			target: "codegen/external",
-			prepare: func(opts *GenOpts) {
-				opts.Target = "codegen/external"
+			target: "external-full",
+			prepare: func(_ testing.TB, opts *GenOpts) {
 				opts.MainPackage = "nrcodegen-server"
 				opts.IncludeMain = true
-				opts.ValidateSpec = false
+				opts.ValidateSpec = false // the spec contains AdditionalItems
 				location := filepath.Join(opts.Target, "models")
+
+				// add some custom model to the generated models
 				addModelsToLocation(t, location, "my_type.go")
 			},
 			verify: func(t testing.TB, target string) {
-				cwd, err := os.Getwd()
-				require.NoError(t, err)
-
-				require.True(t, fileExists(target, filepath.Join("cmd", "nrcodegen-server")))
-
-				err = os.Chdir(filepath.Join(target, "cmd", "nrcodegen-server"))
-				require.NoError(t, err)
-				defer func() {
-					_ = os.Chdir(cwd)
-				}()
+				location := filepath.Join(target, "cmd", "nrcodegen-server")
+				require.True(t, fileExists("", location))
 
 				t.Log("building generated server")
-				p, err := exec.Command("go", "build").CombinedOutput()
-				require.NoErrorf(t, err, string(p))
+				goExecInDir(t, location, "build")
 
-				err = os.Chdir(filepath.Join(cwd, target, "models"))
-				require.NoError(t, err)
+				location = filepath.Join(target, "models")
 
 				t.Log("building generated models")
-				p, err = exec.Command("go", "build").CombinedOutput()
-				require.NoErrorf(t, err, string(p))
-			},
-			clean: func() {
-				_ = os.RemoveAll("codegen")
+				goExecInDir(t, location, "build")
 			},
 		},
 	}
-
-	for name, cas := range cases {
-		thisCas := cas
-
-		t.Run(name, func(t *testing.T) {
-			var captureLog bytes.Buffer
-			log.SetOutput(&captureLog)
-			defer thisCas.warnFailed(t, &captureLog)
-
-			opts := testGenOpts()
-			defer thisCas.prepareTarget(name, "server_test", opts)()
-
-			if thisCas.prepare != nil {
-				thisCas.prepare(opts)
-			}
-
-			t.Logf("generating test server at: %s", opts.Target)
-			err := GenerateServer("", nil, nil, opts)
-			if thisCas.wantError {
-				require.Errorf(t, err, "expected an error for server build fixture: %s", opts.Spec)
-			} else {
-				require.NoError(t, err, "unexpected error for server build fixture: %s", opts.Spec)
-			}
-
-			if thisCas.verify != nil {
-				thisCas.verify(t, opts.Target)
-			}
-
-			if thisCas.clean != nil {
-				thisCas.clean()
-			}
-		})
-	}
 }
 
 func addModelsToLocation(t testing.TB, location, file string) {
-	emkd := os.MkdirAll(location, 0700)
-	require.NoError(t, emkd)
-	erf := ioutil.WriteFile(filepath.Join(location, file), []byte(`
+	// writes some external model to a file to supplement codegen
+	// (test external types)
+	require.NoError(t, os.MkdirAll(location, 0700))
+
+	require.NoError(t, ioutil.WriteFile(filepath.Join(location, file), []byte(`
 package models
 
 import (
@@ -579,6 +535,5 @@ func (MyOtherType) ContextValidate(context.Context, strfmt.Registry) error { ret
 // MyStreamer ...
 type MyStreamer io.Reader
 `),
-		os.ModePerm)
-	require.NoError(t, erf)
+		os.ModePerm))
 }
diff --git a/generator/model_test.go b/generator/model_test.go
index ab392c67..748049f7 100644
--- a/generator/model_test.go
+++ b/generator/model_test.go
@@ -17,8 +17,6 @@ package generator
 import (
 	"bytes"
 	"fmt"
-	"io/ioutil"
-	"log"
 	"os"
 	"path/filepath"
 	"regexp"
@@ -38,51 +36,45 @@ type templateTest struct {
 	template *template.Template
 }
 
-func (tt *templateTest) assertRender(data interface{}, expected string) bool {
+func (tt *templateTest) assertRender(data interface{}, expected string) (success bool) {
 	buf := bytes.NewBuffer(nil)
-	err := tt.template.Execute(buf, data)
-	if !assert.NoError(tt.t, err) {
-		return false
-	}
+	defer func() {
+		success = !tt.t.Failed()
+	}()
+
+	require.NoError(tt.t, tt.template.Execute(buf, data))
+
 	trimmed := strings.TrimLeft(buf.String(), "\n\t ")
 	exp := strings.TrimLeft(expected, "\n\t ")
-	return assert.Equal(tt.t, exp, trimmed)
+	assert.Equal(tt.t, exp, trimmed)
+
+	return
 }
 
 func TestGenerateModel_Sanity(t *testing.T) {
+	t.Parallel()
+
 	// just checks if it can render and format these things
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
+	require.NoError(t, err)
 
-		//k := "Comment"
-		//schema := definitions[k]
+	definitions := specDoc.Spec().Definitions
+
+	t.Run("mode sanity check", func(t *testing.T) {
 		for k, schema := range definitions {
 			opts := opts()
 			genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+			require.NoError(t, err)
 
-			// log.Printf("trying model: %s", k)
-			if assert.NoError(t, err) {
-				//b, _ := json.MarshalIndent(genModel, "", "  ")
-				//fmt.Println(string(b))
-				rendered := bytes.NewBuffer(nil)
-
-				err := templates.MustGet("model").Execute(rendered, genModel)
-				if assert.NoError(t, err, "Unexpected error while rendering models for fixtures/codegen/todolist.models.yml: %v", err) {
-					_, err := opts.LanguageOpts.FormatContent(strings.ToLower(k)+".go", rendered.Bytes())
-					assert.NoError(t, err)
-					//if assert.NoError(t, err) {
-					//fmt.Println(string(formatted))
-					//} else {
-					//fmt.Println(rendered.String())
-					////break
-					//}
-
-					//assert.EqualValues(t, strings.TrimSpace(string(expected)), strings.TrimSpace(string(formatted)))
-				}
-			}
+			rendered := bytes.NewBuffer(nil)
+
+			require.NoErrorf(t, opts.templates.MustGet("model").Execute(rendered, genModel),
+				"Unexpected error while rendering models for fixtures/codegen/todolist.models.yml: %v", err)
+
+			_, err = opts.LanguageOpts.FormatContent(strings.ToLower(k)+".go", rendered.Bytes())
+			require.NoError(t, err)
 		}
-	}
+	})
 }
 
 func TestGenerateModel_DocString(t *testing.T) {
@@ -291,7 +283,6 @@ func TestGenerateModel_Primitives(t *testing.T) {
 
 func TestGenerateModel_Zeroes(t *testing.T) {
 	for _, v := range schTypeGenDataSimple {
-		//t.Logf("Zero for %s: %s", v.Value.GoType, v.Value.Zero())
 		switch v.Value.GoType {
 		// verifying Zero for primitive
 		case "string":
@@ -310,7 +301,6 @@ func TestGenerateModel_Zeroes(t *testing.T) {
 			k.GoType = "myAliasedType"
 			rex = regexp.MustCompile(regexp.QuoteMeta(k.GoType+"("+k.AliasedType) + `{}` + `\)`)
 			assert.True(t, rex.MatchString(k.Zero()))
-			//t.Logf("Zero for %s: %s", k.GoType, k.Zero())
 		case "strfmt.Duration": // akin to integer
 			rex := regexp.MustCompile(regexp.QuoteMeta(v.Value.GoType) + `\(\d*\)`)
 			assert.True(t, rex.MatchString(v.Value.Zero()))
@@ -320,7 +310,6 @@ func TestGenerateModel_Zeroes(t *testing.T) {
 			k.GoType = "myAliasedType"
 			rex = regexp.MustCompile(regexp.QuoteMeta(k.GoType+"("+k.AliasedType) + `\(\d*\)` + `\)`)
 			assert.True(t, rex.MatchString(k.Zero()))
-			//t.Logf("Zero for %s: %s", k.GoType, k.Zero())
 		case "strfmt.Base64": // akin to []byte
 			rex := regexp.MustCompile(regexp.QuoteMeta(v.Value.GoType) + `\(\[\]byte.*\)`)
 			assert.True(t, rex.MatchString(v.Value.Zero()))
@@ -330,7 +319,6 @@ func TestGenerateModel_Zeroes(t *testing.T) {
 			k.GoType = "myAliasedType"
 			rex = regexp.MustCompile(regexp.QuoteMeta(k.GoType+"("+k.AliasedType) + `\(\[\]byte.*\)` + `\)`)
 			assert.True(t, rex.MatchString(k.Zero()))
-			// t.Logf("Zero for %s: %s", k.GoType, k.Zero())
 		case "interface{}":
 			assert.Equal(t, `nil`, v.Value.Zero())
 		case "io.ReadCloser":
@@ -352,343 +340,203 @@ func TestGenerateModel_Zeroes(t *testing.T) {
 				k.GoType = "myAliasedType"
 				rex = regexp.MustCompile(regexp.QuoteMeta(k.GoType+"("+k.AliasedType) + `\(".*"\)` + `\)`)
 				assert.True(t, rex.MatchString(k.Zero()))
-				//t.Logf("Zero for %s: %s", k.GoType, k.Zero())
 			}
 		}
 	}
 }
 func TestGenerateModel_Nota(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "Nota"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				res := buf.String()
-				assertInCode(t, "type Nota map[string]int32", res)
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "Nota"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type Nota map[string]int32", res)
 }
 
 func TestGenerateModel_NotaWithRef(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "NotaWithRef"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("nota_with_ref.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertInCode(t, "type NotaWithRef map[string]Notable", res)
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "NotaWithRef"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	ff, err := opts.LanguageOpts.FormatContent("nota_with_ref.go", buf.Bytes())
+	require.NoError(t, err)
+
+	res := string(ff)
+	assertInCode(t, "type NotaWithRef map[string]Notable", res)
 }
 
 func TestGenerateModel_NotaWithMeta(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "NotaWithMeta"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("nota_with_meta.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertInCode(t, "type NotaWithMeta map[string]NotaWithMetaAnon", res)
-					assertInCode(t, "type NotaWithMetaAnon struct {", res)
-					assertInCode(t, "Comment *string `json:\"comment\"`", res)
-					assertInCode(t, "Count int32 `json:\"count,omitempty\"`", res)
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "NotaWithMeta"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	ff, err := opts.LanguageOpts.FormatContent("nota_with_meta.go", buf.Bytes())
+	require.NoError(t, err)
+
+	res := string(ff)
+	assertInCode(t, "type NotaWithMeta map[string]NotaWithMetaAnon", res)
+	assertInCode(t, "type NotaWithMetaAnon struct {", res)
+	assertInCode(t, "Comment *string `json:\"comment\"`", res)
+	assertInCode(t, "Count int32 `json:\"count,omitempty\"`", res)
 }
 
 func TestGenerateModel_RunParameters(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "RunParameters"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			assert.False(t, genModel.IsAdditionalProperties)
-			assert.True(t, genModel.IsComplexObject)
-			assert.False(t, genModel.IsMap)
-			assert.False(t, genModel.IsAnonymous)
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				res := buf.String()
-				assertInCode(t, "type "+k+" struct {", res)
-				assertInCode(t, "BranchName string `json:\"branch_name,omitempty\"`", res)
-				assertInCode(t, "CommitSha string `json:\"commit_sha,omitempty\"`", res)
-				assertInCode(t, "Refs interface{} `json:\"refs,omitempty\"`", res)
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "RunParameters"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	assert.False(t, genModel.IsAdditionalProperties)
+	assert.True(t, genModel.IsComplexObject)
+	assert.False(t, genModel.IsMap)
+	assert.False(t, genModel.IsAnonymous)
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type "+k+" struct {", res)
+	assertInCode(t, "BranchName string `json:\"branch_name,omitempty\"`", res)
+	assertInCode(t, "CommitSha string `json:\"commit_sha,omitempty\"`", res)
+	assertInCode(t, "Refs interface{} `json:\"refs,omitempty\"`", res)
 }
 
 func TestGenerateModel_NotaWithName(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "NotaWithName"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			assert.True(t, genModel.IsAdditionalProperties)
-			assert.False(t, genModel.IsComplexObject)
-			assert.False(t, genModel.IsMap)
-			assert.False(t, genModel.IsAnonymous)
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				res := buf.String()
-				assertInCode(t, "type "+k+" struct {", res)
-				assertInCode(t, k+" map[string]int32 `json:\"-\"`", res)
-				assertInCode(t, "Name *string `json:\"name\"`", res)
-				assertInCode(t, k+") UnmarshalJSON", res)
-				assertInCode(t, k+") MarshalJSON", res)
-				assertInCode(t, "json.Marshal(stage1)", res)
-				assertInCode(t, "stage1.Name = m.Name", res)
-				assertInCode(t, "json.Marshal(m."+k+")", res)
-				assertInCode(t, "json.Unmarshal(data, &stage1)", res)
-				assertInCode(t, "json.Unmarshal(data, &stage2)", res)
-				assertInCode(t, "json.Unmarshal(v, &toadd)", res)
-				assertInCode(t, "result[k] = toadd", res)
-				assertInCode(t, "m."+k+" = result", res)
-				for _, p := range genModel.Properties {
-					assertInCode(t, "delete(stage2, \""+p.Name+"\")", res)
-				}
+	require.NoError(t, err)
 
-			}
-		}
+	definitions := specDoc.Spec().Definitions
+	k := "NotaWithName"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	assert.True(t, genModel.IsAdditionalProperties)
+	assert.False(t, genModel.IsComplexObject)
+	assert.False(t, genModel.IsMap)
+	assert.False(t, genModel.IsAnonymous)
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type "+k+" struct {", res)
+	assertInCode(t, k+" map[string]int32 `json:\"-\"`", res)
+	assertInCode(t, "Name *string `json:\"name\"`", res)
+	assertInCode(t, k+") UnmarshalJSON", res)
+	assertInCode(t, k+") MarshalJSON", res)
+	assertInCode(t, "json.Marshal(stage1)", res)
+	assertInCode(t, "stage1.Name = m.Name", res)
+	assertInCode(t, "json.Marshal(m."+k+")", res)
+	assertInCode(t, "json.Unmarshal(data, &stage1)", res)
+	assertInCode(t, "json.Unmarshal(data, &stage2)", res)
+	assertInCode(t, "json.Unmarshal(v, &toadd)", res)
+	assertInCode(t, "result[k] = toadd", res)
+	assertInCode(t, "m."+k+" = result", res)
+	for _, p := range genModel.Properties {
+		assertInCode(t, "delete(stage2, \""+p.Name+"\")", res)
 	}
 }
 
 func TestGenerateModel_NotaWithRefRegistry(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "NotaWithRefRegistry"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("nota_with_ref_registry.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertInCode(t, "type "+k+" map[string]map[string]map[string]Notable", res)
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "NotaWithRefRegistry"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	ff, err := opts.LanguageOpts.FormatContent("nota_with_ref_registry.go", buf.Bytes())
+	require.NoError(t, err)
+
+	assertInCode(t, "type "+k+" map[string]map[string]map[string]Notable", string(ff))
 }
 
 func TestGenerateModel_WithCustomTag(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "WithCustomTag"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				res := buf.String()
-				assertInCode(t, "mytag:\"foo,bar\"", res)
-			}
-		}
-	}
-}
+	require.NoError(t, err)
 
-func TestGenerateModel_NotaWithMetaRegistry(t *testing.T) {
-	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "NotaWithMetaRegistry"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("nota_with_meta_registry.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertInCode(t, "type "+k+" map[string]map[string]map[string]NotaWithMetaRegistryAnon", res)
-					assertInCode(t, "type NotaWithMetaRegistryAnon struct {", res)
-					assertInCode(t, "Comment *string `json:\"comment\"`", res)
-					assertInCode(t, "Count int32 `json:\"count,omitempty\"`", res)
-				}
-			}
-		}
-	}
-}
+	definitions := specDoc.Spec().Definitions
+	k := "WithCustomTag"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
 
-func TestGenerateModel_WithMap(t *testing.T) {
-	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		schema := definitions["WithMap"]
-		opts := opts()
-		genModel, err := makeGenDefinition("WithMap", "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			assert.False(t, genModel.HasAdditionalProperties)
-			prop := getDefinitionProperty(genModel, "data")
-			assert.True(t, prop.HasAdditionalProperties)
-			assert.True(t, prop.IsMap)
-			assert.False(t, prop.IsComplexObject)
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				res := buf.String()
-				assertInCode(t, "type WithMap struct {", res)
-				assertInCode(t, "Data map[string]string `json:\"data,omitempty\"`", res)
-			}
-		}
-	}
-}
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
 
-func TestGenerateModel_WithMapInterface(t *testing.T) {
-	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		schema := definitions["WithMapInterface"]
-		opts := opts()
-		genModel, err := makeGenDefinition("WithMapInterface", "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			assert.False(t, genModel.HasAdditionalProperties)
-			prop := getDefinitionProperty(genModel, "extraInfo")
-			assert.True(t, prop.HasAdditionalProperties)
-			assert.True(t, prop.IsMap)
-			assert.False(t, prop.IsComplexObject)
-			assert.Equal(t, "map[string]interface{}", prop.GoType)
-			assert.True(t, prop.Required)
-			assert.True(t, prop.HasValidations)
-			// NOTE(fredbi): NeedsValidation now deprecated
-			//assert.False(t, prop.NeedsValidation)
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				res := buf.String()
-				assertInCode(t, "type WithMapInterface struct {", res)
-				assertInCode(t, "ExtraInfo map[string]interface{} `json:\"extraInfo\"`", res)
-			}
-		}
-	}
+	assertInCode(t, "mytag:\"foo,bar\"", buf.String())
 }
 
-func TestGenerateModel_WithMapRef(t *testing.T) {
+func TestGenerateModel_NotaWithMetaRegistry(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "WithMapRef"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			assert.False(t, genModel.HasAdditionalProperties)
-			prop := getDefinitionProperty(genModel, "data")
-			assert.True(t, prop.HasAdditionalProperties)
-			assert.True(t, prop.IsMap)
-			assert.False(t, prop.IsComplexObject)
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				res := buf.String()
-				assertInCode(t, "type "+k+" struct {", res)
-				assertInCode(t, "Data map[string]Notable `json:\"data,omitempty\"`", res)
-			}
-		}
-	}
-}
+	require.NoError(t, err)
 
-func TestGenerateModel_WithMapComplex(t *testing.T) {
-	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "WithMapComplex"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			assert.False(t, genModel.HasAdditionalProperties)
-			prop := getDefinitionProperty(genModel, "data")
-			assert.True(t, prop.HasAdditionalProperties)
-			assert.True(t, prop.IsMap)
-			assert.False(t, prop.IsComplexObject)
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				res := buf.String()
-				assertInCode(t, "type "+k+" struct {", res)
-				assertInCode(t, "Data map[string]"+k+"DataAnon `json:\"data,omitempty\"`", res)
-			}
-		}
-	}
-}
+	definitions := specDoc.Spec().Definitions
+	k := "NotaWithMetaRegistry"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
 
-func TestGenerateModel_WithMapRegistry(t *testing.T) {
-	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		schema := definitions["WithMapRegistry"]
-		opts := opts()
-		genModel, err := makeGenDefinition("WithMap", "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			assert.False(t, genModel.HasAdditionalProperties)
-			prop := getDefinitionProperty(genModel, "data")
-			assert.True(t, prop.HasAdditionalProperties)
-			assert.True(t, prop.IsMap)
-			assert.False(t, prop.IsComplexObject)
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				res := buf.String()
-				assertInCode(t, "type WithMap struct {", res)
-				assertInCode(t, "Data map[string]map[string]map[string]string `json:\"data,omitempty\"`", res)
-			}
-		}
-	}
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	ff, err := opts.LanguageOpts.FormatContent("nota_with_meta_registry.go", buf.Bytes())
+	require.NoError(t, err)
+
+	res := string(ff)
+	assertInCode(t, "type "+k+" map[string]map[string]map[string]NotaWithMetaRegistryAnon", res)
+	assertInCode(t, "type NotaWithMetaRegistryAnon struct {", res)
+	assertInCode(t, "Comment *string `json:\"comment\"`", res)
+	assertInCode(t, "Count int32 `json:\"count,omitempty\"`", res)
 }
 
-func TestGenerateModel_WithMapRegistryRef(t *testing.T) {
+func TestGenerateModel_WithMap(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
 	if assert.NoError(t, err) {
 		definitions := specDoc.Spec().Definitions
-		k := "WithMapRegistryRef"
-		schema := definitions[k]
+		schema := definitions["WithMap"]
 		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+		genModel, err := makeGenDefinition("WithMap", "models", schema, specDoc, opts)
 		if assert.NoError(t, err) {
 			assert.False(t, genModel.HasAdditionalProperties)
 			prop := getDefinitionProperty(genModel, "data")
@@ -699,204 +547,322 @@ func TestGenerateModel_WithMapRegistryRef(t *testing.T) {
 			err := templates.MustGet("model").Execute(buf, genModel)
 			if assert.NoError(t, err) {
 				res := buf.String()
-				assertInCode(t, "type "+k+" struct {", res)
-				assertInCode(t, "Data map[string]map[string]map[string]Notable `json:\"data,omitempty\"`", res)
+				assertInCode(t, "type WithMap struct {", res)
+				assertInCode(t, "Data map[string]string `json:\"data,omitempty\"`", res)
 			}
 		}
 	}
 }
 
+func TestGenerateModel_WithMapInterface(t *testing.T) {
+	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	schema := definitions["WithMapInterface"]
+	opts := opts()
+	genModel, err := makeGenDefinition("WithMapInterface", "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	assert.False(t, genModel.HasAdditionalProperties)
+	prop := getDefinitionProperty(genModel, "extraInfo")
+	assert.True(t, prop.HasAdditionalProperties)
+	assert.True(t, prop.IsMap)
+	assert.False(t, prop.IsComplexObject)
+	assert.Equal(t, "map[string]interface{}", prop.GoType)
+	assert.True(t, prop.Required)
+	assert.True(t, prop.HasValidations)
+
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type WithMapInterface struct {", res)
+	assertInCode(t, "ExtraInfo map[string]interface{} `json:\"extraInfo\"`", res)
+}
+
+func TestGenerateModel_WithMapRef(t *testing.T) {
+	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "WithMapRef"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	assert.False(t, genModel.HasAdditionalProperties)
+	prop := getDefinitionProperty(genModel, "data")
+	assert.True(t, prop.HasAdditionalProperties)
+	assert.True(t, prop.IsMap)
+	assert.False(t, prop.IsComplexObject)
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type "+k+" struct {", res)
+	assertInCode(t, "Data map[string]Notable `json:\"data,omitempty\"`", res)
+}
+
+func TestGenerateModel_WithMapComplex(t *testing.T) {
+	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "WithMapComplex"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	assert.False(t, genModel.HasAdditionalProperties)
+	prop := getDefinitionProperty(genModel, "data")
+	assert.True(t, prop.HasAdditionalProperties)
+	assert.True(t, prop.IsMap)
+	assert.False(t, prop.IsComplexObject)
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type "+k+" struct {", res)
+	assertInCode(t, "Data map[string]"+k+"DataAnon `json:\"data,omitempty\"`", res)
+}
+
+func TestGenerateModel_WithMapRegistry(t *testing.T) {
+	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	schema := definitions["WithMapRegistry"]
+	opts := opts()
+	genModel, err := makeGenDefinition("WithMap", "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	assert.False(t, genModel.HasAdditionalProperties)
+	prop := getDefinitionProperty(genModel, "data")
+	assert.True(t, prop.HasAdditionalProperties)
+	assert.True(t, prop.IsMap)
+	assert.False(t, prop.IsComplexObject)
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type WithMap struct {", res)
+	assertInCode(t, "Data map[string]map[string]map[string]string `json:\"data,omitempty\"`", res)
+}
+
+func TestGenerateModel_WithMapRegistryRef(t *testing.T) {
+	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "WithMapRegistryRef"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	assert.False(t, genModel.HasAdditionalProperties)
+	prop := getDefinitionProperty(genModel, "data")
+	assert.True(t, prop.HasAdditionalProperties)
+	assert.True(t, prop.IsMap)
+	assert.False(t, prop.IsComplexObject)
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type "+k+" struct {", res)
+	assertInCode(t, "Data map[string]map[string]map[string]Notable `json:\"data,omitempty\"`", res)
+}
+
 func TestGenerateModel_WithMapComplexRegistry(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "WithMapComplexRegistry"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			assert.False(t, genModel.HasAdditionalProperties)
-			prop := getDefinitionProperty(genModel, "data")
-			assert.True(t, prop.HasAdditionalProperties)
-			assert.True(t, prop.IsMap)
-			assert.False(t, prop.IsComplexObject)
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				res := buf.String()
-				assertInCode(t, "type "+k+" struct {", res)
-				assertInCode(t, "Data map[string]map[string]map[string]"+k+"DataAnon `json:\"data,omitempty\"`", res)
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "WithMapComplexRegistry"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	assert.False(t, genModel.HasAdditionalProperties)
+	prop := getDefinitionProperty(genModel, "data")
+	assert.True(t, prop.HasAdditionalProperties)
+	assert.True(t, prop.IsMap)
+	assert.False(t, prop.IsComplexObject)
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type "+k+" struct {", res)
+	assertInCode(t, "Data map[string]map[string]map[string]"+k+"DataAnon `json:\"data,omitempty\"`", res)
 }
 
 func TestGenerateModel_WithAdditional(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "WithAdditional"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) && assert.NotEmpty(t, genModel.ExtraSchemas) {
-			assert.False(t, genModel.HasAdditionalProperties)
-			assert.False(t, genModel.IsMap)
-			assert.False(t, genModel.IsAdditionalProperties)
-			assert.True(t, genModel.IsComplexObject)
-
-			sch := genModel.ExtraSchemas[0]
-			assert.True(t, sch.HasAdditionalProperties)
-			assert.False(t, sch.IsMap)
-			assert.True(t, sch.IsAdditionalProperties)
-			assert.False(t, sch.IsComplexObject)
+	require.NoError(t, err)
 
-			if assert.NotNil(t, sch.AdditionalProperties) {
-				prop := findProperty(genModel.Properties, "data")
-				assert.False(t, prop.HasAdditionalProperties)
-				assert.False(t, prop.IsMap)
-				assert.False(t, prop.IsAdditionalProperties)
-				assert.True(t, prop.IsComplexObject)
-				buf := bytes.NewBuffer(nil)
-				err := templates.MustGet("model").Execute(buf, genModel)
-				if assert.NoError(t, err) {
-					res := buf.String()
-					assertInCode(t, "type "+k+" struct {", res)
-					assertInCode(t, "Data *"+k+"Data `json:\"data,omitempty\"`", res)
-					assertInCode(t, "type "+k+"Data struct {", res)
-					assertInCode(t, k+"Data map[string]string `json:\"-\"`", res)
-					assertInCode(t, "Name *string `json:\"name\"`", res)
-					assertInCode(t, k+"Data) UnmarshalJSON", res)
-					assertInCode(t, k+"Data) MarshalJSON", res)
-					assertInCode(t, "json.Marshal(stage1)", res)
-					assertInCode(t, "stage1.Name = m.Name", res)
-					assertInCode(t, "json.Marshal(m."+k+"Data)", res)
-					assertInCode(t, "json.Unmarshal(data, &stage1)", res)
-					assertInCode(t, "json.Unmarshal(data, &stage2)", res)
-					assertInCode(t, "json.Unmarshal(v, &toadd)", res)
-					assertInCode(t, "result[k] = toadd", res)
-					assertInCode(t, "m."+k+"Data = result", res)
-					for _, p := range sch.Properties {
-						assertInCode(t, "delete(stage2, \""+p.Name+"\")", res)
-					}
-				}
-			}
-		}
+	definitions := specDoc.Spec().Definitions
+	k := "WithAdditional"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+	require.NotEmpty(t, genModel.ExtraSchemas)
+
+	assert.False(t, genModel.HasAdditionalProperties)
+	assert.False(t, genModel.IsMap)
+	assert.False(t, genModel.IsAdditionalProperties)
+	assert.True(t, genModel.IsComplexObject)
+
+	sch := genModel.ExtraSchemas[0]
+	assert.True(t, sch.HasAdditionalProperties)
+	assert.False(t, sch.IsMap)
+	assert.True(t, sch.IsAdditionalProperties)
+	assert.False(t, sch.IsComplexObject)
+
+	require.NotNil(t, sch.AdditionalProperties)
+
+	prop := findProperty(genModel.Properties, "data")
+	assert.False(t, prop.HasAdditionalProperties)
+	assert.False(t, prop.IsMap)
+	assert.False(t, prop.IsAdditionalProperties)
+	assert.True(t, prop.IsComplexObject)
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type "+k+" struct {", res)
+	assertInCode(t, "Data *"+k+"Data `json:\"data,omitempty\"`", res)
+	assertInCode(t, "type "+k+"Data struct {", res)
+	assertInCode(t, k+"Data map[string]string `json:\"-\"`", res)
+	assertInCode(t, "Name *string `json:\"name\"`", res)
+	assertInCode(t, k+"Data) UnmarshalJSON", res)
+	assertInCode(t, k+"Data) MarshalJSON", res)
+	assertInCode(t, "json.Marshal(stage1)", res)
+	assertInCode(t, "stage1.Name = m.Name", res)
+	assertInCode(t, "json.Marshal(m."+k+"Data)", res)
+	assertInCode(t, "json.Unmarshal(data, &stage1)", res)
+	assertInCode(t, "json.Unmarshal(data, &stage2)", res)
+	assertInCode(t, "json.Unmarshal(v, &toadd)", res)
+	assertInCode(t, "result[k] = toadd", res)
+	assertInCode(t, "m."+k+"Data = result", res)
+
+	for _, p := range sch.Properties {
+		assertInCode(t, "delete(stage2, \""+p.Name+"\")", res)
 	}
 }
 
 func TestGenerateModel_JustRef(t *testing.T) {
 	tt := templateTest{t, templates.MustGet("model").Lookup("schema")}
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		schema := definitions["JustRef"]
-		opts := opts()
-		genModel, err := makeGenDefinition("JustRef", "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			assert.NotEmpty(t, genModel.AllOf)
-			assert.True(t, genModel.IsComplexObject)
-			assert.Equal(t, "JustRef", genModel.Name)
-			assert.Equal(t, "JustRef", genModel.GoType)
-			buf := bytes.NewBuffer(nil)
-			err = tt.template.Execute(buf, genModel)
-			assert.NoError(t, err)
-			res := buf.String()
-			assertInCode(t, "type JustRef struct {", res)
-			assertInCode(t, "Notable", res)
-		}
-	}
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	schema := definitions["JustRef"]
+	opts := opts()
+	genModel, err := makeGenDefinition("JustRef", "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	assert.NotEmpty(t, genModel.AllOf)
+	assert.True(t, genModel.IsComplexObject)
+	assert.Equal(t, "JustRef", genModel.Name)
+	assert.Equal(t, "JustRef", genModel.GoType)
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, tt.template.Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type JustRef struct {", res)
+	assertInCode(t, "Notable", res)
 }
 
 func TestGenerateModel_WithRef(t *testing.T) {
 	tt := templateTest{t, templates.MustGet("model").Lookup("schema")}
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		schema := definitions["WithRef"]
-		opts := opts()
-		genModel, err := makeGenDefinition("WithRef", "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			assert.True(t, genModel.IsComplexObject)
-			assert.Equal(t, "WithRef", genModel.Name)
-			assert.Equal(t, "WithRef", genModel.GoType)
-			buf := bytes.NewBuffer(nil)
-			err = tt.template.Execute(buf, genModel)
-			assert.NoError(t, err)
-			res := buf.String()
-			assertInCode(t, "type WithRef struct {", res)
-			assertInCode(t, "Notes *Notable `json:\"notes,omitempty\"`", res)
-		}
-	}
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	schema := definitions["WithRef"]
+	opts := opts()
+	genModel, err := makeGenDefinition("WithRef", "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	assert.True(t, genModel.IsComplexObject)
+	assert.Equal(t, "WithRef", genModel.Name)
+	assert.Equal(t, "WithRef", genModel.GoType)
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, tt.template.Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type WithRef struct {", res)
+	assertInCode(t, "Notes *Notable `json:\"notes,omitempty\"`", res)
 }
 
 func TestGenerateModel_WithNullableRef(t *testing.T) {
 	tt := templateTest{t, templates.MustGet("model").Lookup("schema")}
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		schema := definitions["WithNullableRef"]
-		opts := opts()
-		genModel, err := makeGenDefinition("WithNullableRef", "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			assert.True(t, genModel.IsComplexObject)
-			assert.Equal(t, "WithNullableRef", genModel.Name)
-			assert.Equal(t, "WithNullableRef", genModel.GoType)
-			prop := getDefinitionProperty(genModel, "notes")
-			assert.True(t, prop.IsNullable)
-			assert.True(t, prop.IsComplexObject)
-			buf := bytes.NewBuffer(nil)
-			err = tt.template.Execute(buf, genModel)
-			assert.NoError(t, err)
-			res := buf.String()
-			assertInCode(t, "type WithNullableRef struct {", res)
-			assertInCode(t, "Notes *Notable `json:\"notes,omitempty\"`", res)
-		}
-	}
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	schema := definitions["WithNullableRef"]
+	opts := opts()
+	genModel, err := makeGenDefinition("WithNullableRef", "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	assert.True(t, genModel.IsComplexObject)
+	assert.Equal(t, "WithNullableRef", genModel.Name)
+	assert.Equal(t, "WithNullableRef", genModel.GoType)
+	prop := getDefinitionProperty(genModel, "notes")
+	assert.True(t, prop.IsNullable)
+	assert.True(t, prop.IsComplexObject)
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, tt.template.Execute(buf, genModel))
+
+	res := buf.String()
+	assertInCode(t, "type WithNullableRef struct {", res)
+	assertInCode(t, "Notes *Notable `json:\"notes,omitempty\"`", res)
 }
 
 func TestGenerateModel_Scores(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "Scores"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("scores.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertInCode(t, "type Scores []float32", res)
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "Scores"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	ff, err := opts.LanguageOpts.FormatContent("scores.go", buf.Bytes())
+	require.NoError(t, err)
+
+	assertInCode(t, "type Scores []float32", string(ff))
 }
 
 func TestGenerateModel_JaggedScores(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.models.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "JaggedScores"
-		schema := definitions[k]
-		opts := opts()
-		genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("jagged_scores.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertInCode(t, "type JaggedScores [][][]float32", res)
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "JaggedScores"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	ff, err := opts.LanguageOpts.FormatContent("jagged_scores.go", buf.Bytes())
+	require.NoError(t, err)
+
+	assertInCode(t, "type JaggedScores [][][]float32", string(ff))
 }
 
 func TestGenerateModel_Notables(t *testing.T) {
@@ -2332,8 +2298,7 @@ func TestGenModel_Issue1409(t *testing.T) {
 
 // This tests makes sure model definitions from inline schema in response are properly flattened and get validation
 func TestGenModel_Issue866(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	specDoc, err := loads.Spec("../fixtures/bugs/866/fixture-866.yaml")
 	if assert.NoError(t, err) {
@@ -2650,91 +2615,97 @@ func TestGenModel_XMLStructTags_WithXML(t *testing.T) {
 
 func TestGenModel_XMLStructTags_Explicit(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/xml-model.yml")
-	if assert.NoError(t, err) {
-		definitions := specDoc.Spec().Definitions
-		k := "XmlWithAttribute"
-		opts := opts()
+	require.NoError(t, err)
 
-		genModel, err := makeGenDefinition(k, "models", definitions[k], specDoc, opts)
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			err := templates.MustGet("model").Execute(buf, genModel)
-			if assert.NoError(t, err) {
-				ct, err := opts.LanguageOpts.FormatContent("xml_with_attribute.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ct)
-					assertInCode(t, "Author *string `json:\"author\"`", res)
-					assertInCode(t, "Children []*XMLChild `json:\"children\"`", res)
-					assertInCode(t, "ID int64 `json:\"id,omitempty\" xml:\"id,attr,omitempty\"`", res)
-					assertInCode(t, "IsPublished *bool `json:\"isPublished\" xml:\"published,attr\"`", res)
-					assertInCode(t, "SingleChild *XMLChild `json:\"singleChild,omitempty\"`", res)
-					assertInCode(t, "Title string `json:\"title,omitempty\" xml:\"xml-title,omitempty\"`", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	definitions := specDoc.Spec().Definitions
+	k := "XmlWithAttribute"
+	opts := opts()
+
+	genModel, err := makeGenDefinition(k, "models", definitions[k], specDoc, opts)
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	ct, err := opts.LanguageOpts.FormatContent("xml_with_attribute.go", buf.Bytes())
+	require.NoErrorf(t, err, "format error: %v\n%s", err, buf.String())
+
+	res := string(ct)
+	assertInCode(t, "Author *string `json:\"author\"`", res)
+	assertInCode(t, "Children []*XMLChild `json:\"children\"`", res)
+	assertInCode(t, "ID int64 `json:\"id,omitempty\" xml:\"id,attr,omitempty\"`", res)
+	assertInCode(t, "IsPublished *bool `json:\"isPublished\" xml:\"published,attr\"`", res)
+	assertInCode(t, "SingleChild *XMLChild `json:\"singleChild,omitempty\"`", res)
+	assertInCode(t, "Title string `json:\"title,omitempty\" xml:\"xml-title,omitempty\"`", res)
 }
 
 func TestGenerateModels(t *testing.T) {
+	t.Parallel()
+	defer discardOutput()()
+
+	cwd := testCwd(t)
+	const root = "generated_models"
 	defer func() {
-		log.SetOutput(os.Stdout)
+		_ = os.RemoveAll(filepath.Join(cwd, root))
 	}()
 
-	cases := map[string]generateFixture{
-		"allDefinitions": {
-			spec:   "../fixtures/bugs/1042/fixture-1042.yaml",
-			target: "../fixtures/bugs/1042",
-			verify: func(t testing.TB, target string) {
-				target = filepath.Join(target, defaultModelsTarget)
-				require.True(t, fileExists(target, ""))
-				assert.True(t, fileExists(target, "a.go"))
-				assert.True(t, fileExists(target, "b.go"))
+	t.Run("generate models", func(t *testing.T) {
+		cases := map[string]generateFixture{
+			"allDefinitions": {
+				spec:   "../fixtures/bugs/1042/fixture-1042.yaml",
+				target: "../fixtures/bugs/1042",
+				verify: func(t testing.TB, target string) {
+					target = filepath.Join(target, defaultModelsTarget)
+					require.True(t, fileExists(target, ""))
+					assert.True(t, fileExists(target, "a.go"))
+					assert.True(t, fileExists(target, "b.go"))
+				},
 			},
-		},
-		"acceptDefinitions": {
-			spec:   "../fixtures/enhancements/2333/fixture-definitions.yaml",
-			target: "../fixtures/enhancements/2333",
-			prepare: func(opts *GenOpts) {
-				opts.AcceptDefinitionsOnly = true
+			"acceptDefinitions": {
+				spec:   "../fixtures/enhancements/2333/fixture-definitions.yaml",
+				target: "../fixtures/enhancements/2333",
+				prepare: func(_ testing.TB, opts *GenOpts) {
+					opts.AcceptDefinitionsOnly = true
+				},
+				verify: func(t testing.TB, target string) {
+					target = filepath.Join(target, defaultModelsTarget)
+					require.True(t, fileExists(target, ""))
+					assert.True(t, fileExists(target, "model_interface.go"))
+					assert.True(t, fileExists(target, "records_model.go"))
+					assert.True(t, fileExists(target, "records_model_with_max.go"))
+					assert.False(t, fileExists(target, "restapi"))
+				},
 			},
-			verify: func(t testing.TB, target string) {
-				target = filepath.Join(target, defaultModelsTarget)
-				require.True(t, fileExists(target, ""))
-				assert.True(t, fileExists(target, "model_interface.go"))
-				assert.True(t, fileExists(target, "records_model.go"))
-				assert.True(t, fileExists(target, "records_model_with_max.go"))
-				assert.False(t, fileExists(target, "restapi"))
-			},
-		},
-	}
-	for name, cas := range cases {
-		thisCas := cas
+		}
+		for k, cas := range cases {
+			name := k
+			thisCas := cas
 
-		t.Run(name, func(t *testing.T) {
-			var captureLog bytes.Buffer
-			log.SetOutput(&captureLog)
-			defer thisCas.warnFailed(t, &captureLog)
+			t.Run(name, func(t *testing.T) {
+				t.Parallel()
 
-			opts := testGenOpts()
-			defer thisCas.prepareTarget(name, "model_test", opts)()
+				defer thisCas.warnFailed(t)
 
-			if thisCas.prepare != nil {
-				thisCas.prepare(opts)
-			}
+				opts := testGenOpts()
+				defer thisCas.prepareTarget(t, name, "model_test", root, opts)()
 
-			t.Logf("generating test models at: %s", opts.Target)
-			err := GenerateModels([]string{"", ""}, opts) // NOTE: generate all models, ignore ""
-			if thisCas.wantError {
-				require.Errorf(t, err, "expected an error for models build fixture: %s", opts.Spec)
-			} else {
-				require.NoError(t, err, "unexpected error for models build fixture: %s", opts.Spec)
-			}
+				if thisCas.prepare != nil {
+					thisCas.prepare(t, opts)
+				}
 
-			if thisCas.verify != nil {
-				thisCas.verify(t, opts.Target)
-			}
-		})
-	}
+				t.Logf("generating test models at: %s", opts.Target)
+
+				err := GenerateModels([]string{"", ""}, opts) // NOTE: generate all models, ignore ""
+				if thisCas.wantError {
+					require.Errorf(t, err, "expected an error for models build fixture: %s", opts.Spec)
+				} else {
+					require.NoError(t, err, "unexpected error for models build fixture: %s", opts.Spec)
+				}
+
+				if thisCas.verify != nil {
+					thisCas.verify(t, opts.Target)
+				}
+			})
+		}
+	})
 }
diff --git a/generator/moreschemavalidation_test.go b/generator/moreschemavalidation_test.go
index a833b67f..1e0c380c 100644
--- a/generator/moreschemavalidation_test.go
+++ b/generator/moreschemavalidation_test.go
@@ -41,6 +41,49 @@ type modelExpectations struct {
 	ExpectFailure    bool
 }
 
+func (m modelExpectations) ExpectLogs() bool {
+	// does this test case assert output?
+	return len(m.ExpectedLogs) > 0 || len(m.NotExpectedLogs) > 0
+}
+
+func (m modelExpectations) AssertModelLogs(t testing.TB, msg, definitionName, fixtureSpec string) {
+	// assert logged output
+	for line, logLine := range m.ExpectedLogs {
+		if !assertInCode(t, strings.TrimSpace(logLine), msg) {
+			t.Logf("log expected did not match for definition %q in fixture %s at (fixture) log line %d", definitionName, fixtureSpec, line)
+		}
+	}
+
+	for line, logLine := range m.NotExpectedLogs {
+		if !assertNotInCode(t, strings.TrimSpace(logLine), msg) {
+			t.Logf("log unexpectedly matched for definition %q in fixture %s at (fixture) log line %d", definitionName, fixtureSpec, line)
+		}
+	}
+
+	if t.Failed() {
+		t.FailNow()
+	}
+}
+
+func (m modelExpectations) AssertModelCodegen(t testing.TB, msg, definitionName, fixtureSpec string) {
+	// assert generated code
+	for line, codeLine := range m.ExpectedLines {
+		if !assertInCode(t, strings.TrimSpace(codeLine), msg) {
+			t.Logf("code expected did not match for definition %q in fixture %s at (fixture) line %d", definitionName, fixtureSpec, line)
+		}
+	}
+
+	for line, codeLine := range m.NotExpectedLines {
+		if !assertNotInCode(t, strings.TrimSpace(codeLine), msg) {
+			t.Logf("code unexpectedly matched for definition %q in fixture %s at (fixture) line %d", definitionName, fixtureSpec, line)
+		}
+	}
+
+	if t.Failed() {
+		t.FailNow()
+	}
+}
+
 // modelTestRun is a test structure to configure generations options to test a spec
 type modelTestRun struct {
 	FixtureOpts *GenOpts
@@ -57,6 +100,7 @@ func (r *modelTestRun) AddExpectations(file string, expectedCode, notExpectedCod
 		def.NotExpectedLogs = append(def.NotExpectedLogs, notExpectedLogs...)
 		return
 	}
+
 	r.Definitions[k] = &modelExpectations{
 		GeneratedFile:    file,
 		ExpectedLines:    expectedCode,
@@ -143,7 +187,7 @@ func newModelFixture(specFile string, description string) *modelFixture {
 // all tested specs: init at the end of this source file
 // you may append to those with different initXXX() funcs below.
 var (
-	modelTestMutex = &sync.Mutex{}
+	modelTestMutex = &sync.Mutex{} // mutex to protect log capture
 	testedModels   []*modelFixture
 
 	// convenient vars for (not) matching some lines
@@ -318,221 +362,111 @@ func TestMoreModelValidations(t *testing.T) {
 	defer func() {
 		log.SetOutput(os.Stdout)
 	}()
-	continueOnErrors := false
-	initModelFixtures()
 
-	dassert := assert.New(t)
+	initModelFixtures()
 
 	t.Logf("INFO: model specs tested: %d", len(testedModels))
-	for _, fixt := range testedModels {
-		fixture := fixt
+	for _, toPin := range testedModels {
+		fixture := toPin
 		if fixture.SpecFile == "" {
 			continue
 		}
 		fixtureSpec := fixture.SpecFile
 		runTitle := strings.Join([]string{"codegen", strings.TrimSuffix(path.Base(fixtureSpec), path.Ext(fixtureSpec))}, "-")
+
 		t.Run(runTitle, func(t *testing.T) {
-			// gave up with parallel testing: when $ref analysis is involved, it is not possible to to parallelize
-			//t.Parallel()
+			t.Parallel()
 			log.SetOutput(ioutil.Discard)
+
 			for _, fixtureRun := range fixture.Runs {
-				// workaround race condition with underlying pkg: go-openapi/spec works with a global cache
-				// which does not support concurrent use for different specs.
-				//modelTestMutex.Lock()
 				opts := fixtureRun.FixtureOpts
 				opts.Spec = fixtureSpec
 				// this is the expanded or flattened spec
-				newSpecDoc, er0 := opts.validateAndFlattenSpec()
-				if !dassert.NoErrorf(er0, "could not expand/flatten fixture %s: %v", fixtureSpec, er0) {
-					//modelTestMutex.Unlock()
-					t.FailNow()
-					return
-				}
-				//modelTestMutex.Unlock()
+				newSpecDoc, err := opts.validateAndFlattenSpec()
+				require.NoErrorf(t, err, "could not expand/flatten fixture %s: %v", fixtureSpec, err)
+
 				definitions := newSpecDoc.Spec().Definitions
 				for k, fixtureExpectations := range fixtureRun.Definitions {
 					// pick definition to test
-					var schema *spec.Schema
-					var definitionName string
-					for def, s := range definitions {
-						// please do not inject fixtures with case conflicts on defs...
-						// this one is just easier to retrieve model back from file names when capturing
-						// the generated code.
-						mangled := swag.ToJSONName(def)
-						if strings.EqualFold(mangled, k) {
-							schema = &s
-							definitionName = def
-							break
-						}
-					}
-					if !dassert.NotNil(schema, "expected to find definition %q in model fixture %s", k, fixtureSpec) {
-						//modelTestMutex.Unlock()
-						t.FailNow()
-						return
-					}
-					checkDefinitionCodegen(t, definitionName, fixtureSpec, schema, newSpecDoc, opts, fixtureExpectations, continueOnErrors)
+					definitionName, schema := findTestDefinition(k, definitions)
+					require.NotNilf(t, schema, "expected to find definition %q in model fixture %s", k, fixtureSpec)
+
+					checkDefinitionCodegen(t, definitionName, fixtureSpec, schema, newSpecDoc, opts, fixtureExpectations)
 				}
 			}
 		})
 	}
 }
 
-func checkContinue(t *testing.T, continueOnErrors bool) {
-	if continueOnErrors {
-		t.Fail()
-	} else {
-		t.FailNow()
+func findTestDefinition(k string, definitions spec.Definitions) (string, *spec.Schema) {
+	var (
+		schema         *spec.Schema
+		definitionName string
+	)
+
+	for def, s := range definitions {
+		// please do not inject fixtures with case conflicts on defs...
+		// this one is just easier to retrieve model back from file names when capturing
+		// the generated code.
+		mangled := swag.ToJSONName(def)
+		if strings.EqualFold(mangled, k) {
+			definition := s
+			schema = &definition
+			definitionName = def
+			break
+		}
 	}
+	return definitionName, schema
 }
 
-func checkDefinitionCodegen(t *testing.T, definitionName, fixtureSpec string, schema *spec.Schema, specDoc *loads.Document, opts *GenOpts, fixtureExpectations *modelExpectations, continueOnErrors bool) {
+func checkDefinitionCodegen(t testing.TB, definitionName, fixtureSpec string, schema *spec.Schema, specDoc *loads.Document, opts *GenOpts, fixtureExpectations *modelExpectations) {
 	// prepare assertions on log output (e.g. generation warnings)
 	var logCapture bytes.Buffer
 	var msg string
-	dassert := assert.New(t)
-	if len(fixtureExpectations.ExpectedLogs) > 0 || len(fixtureExpectations.NotExpectedLogs) > 0 {
+
+	if fixtureExpectations.ExpectLogs() {
 		// lock when capturing shared log resource (hopefully not for all testcases)
 		modelTestMutex.Lock()
 		log.SetOutput(&logCapture)
+
+		defer func() {
+			log.SetOutput(ioutil.Discard)
+			modelTestMutex.Unlock()
+		}()
 	}
 
 	// generate the schema for this definition
-	genModel, er1 := makeGenDefinition(definitionName, "models", *schema, specDoc, opts)
-	if len(fixtureExpectations.ExpectedLogs) > 0 || len(fixtureExpectations.NotExpectedLogs) > 0 {
+	genModel, err := makeGenDefinition(definitionName, "models", *schema, specDoc, opts)
+	if fixtureExpectations.ExpectLogs() {
 		msg = logCapture.String()
-		log.SetOutput(ioutil.Discard)
-		modelTestMutex.Unlock()
 	}
 
-	if fixtureExpectations.ExpectFailure && !dassert.Errorf(er1, "Expected an error during generation of definition %q from spec fixture %s", definitionName, fixtureSpec) {
+	if fixtureExpectations.ExpectFailure {
 		// expected an error here, and it has not happened
-		checkContinue(t, continueOnErrors)
-		return
+		require.Errorf(t, err, "Expected an error during generation of definition %q from spec fixture %s", definitionName, fixtureSpec)
 	}
-	if !dassert.NoErrorf(er1, "could not generate model definition %q from spec fixture %s: %v", definitionName, fixtureSpec, er1) {
-		// expected smooth generation
-		checkContinue(t, continueOnErrors)
-		return
-	}
-	if len(fixtureExpectations.ExpectedLogs) > 0 || len(fixtureExpectations.NotExpectedLogs) > 0 {
-		// assert logged output
-		for line, logLine := range fixtureExpectations.ExpectedLogs {
-			if !assertInCode(t, strings.TrimSpace(logLine), msg) {
-				t.Logf("log expected did not match for definition %q in fixture %s at (fixture) log line %d", definitionName, fixtureSpec, line)
-			}
-		}
-		for line, logLine := range fixtureExpectations.NotExpectedLogs {
-			if !assertNotInCode(t, strings.TrimSpace(logLine), msg) {
-				t.Logf("log unexpectedly matched for definition %q in fixture %s at (fixture) log line %d", definitionName, fixtureSpec, line)
-			}
-		}
-		if t.Failed() && !continueOnErrors {
-			t.FailNow()
-			return
-		}
+
+	// expected smooth generation
+	require.NoErrorf(t, err, "could not generate model definition %q from spec fixture %s: %v", definitionName, fixtureSpec, err)
+
+	if fixtureExpectations.ExpectLogs() {
+		fixtureExpectations.AssertModelLogs(t, msg, definitionName, fixtureSpec)
 	}
 
 	// execute the model template with this schema
 	buf := bytes.NewBuffer(nil)
-	er2 := templates.MustGet("model").Execute(buf, genModel)
-	if !dassert.NoErrorf(er2, "could not render model template for definition %q in spec fixture %s: %v", definitionName, fixtureSpec, er2) {
-		checkContinue(t, continueOnErrors)
-		return
-	}
+	err = templates.MustGet("model").Execute(buf, genModel)
+	require.NoErrorf(t, err, "could not render model template for definition %q in spec fixture %s: %v", definitionName, fixtureSpec, err)
+
 	outputName := fixtureExpectations.GeneratedFile
 	if outputName == "" {
 		outputName = swag.ToFileName(definitionName) + ".go"
 	}
 
 	// run goimport, gofmt on the generated code
-	formatted, er3 := opts.LanguageOpts.FormatContent(outputName, buf.Bytes())
-	if !dassert.NoErrorf(er3, "could not render model template for definition %q in spec fixture %s: %v", definitionName, fixtureSpec, er2) {
-		checkContinue(t, continueOnErrors)
-		return
-	}
-
-	// asserts generated code (see fixture file)
-	res := string(formatted)
-	for line, codeLine := range fixtureExpectations.ExpectedLines {
-		if !assertInCode(t, strings.TrimSpace(codeLine), res) {
-			t.Logf("code expected did not match for definition %q in fixture %s at (fixture) line %d", definitionName, fixtureSpec, line)
-		}
-	}
-	for line, codeLine := range fixtureExpectations.NotExpectedLines {
-		if !assertNotInCode(t, strings.TrimSpace(codeLine), res) {
-			t.Logf("code unexpectedly matched for definition %q in fixture %s at (fixture) line %d", definitionName, fixtureSpec, line)
-		}
-	}
-	if t.Failed() && !continueOnErrors {
-		t.FailNow()
-		return
-	}
-}
+	formatted, err := opts.LanguageOpts.FormatContent(outputName, buf.Bytes())
+	require.NoErrorf(t, err, "could not render model template for definition %q in spec fixture %s: %v", definitionName, fixtureSpec, err)
 
-/*
-// Gave up with parallel testing
-// TestModelRace verifies how much of the load/expand/flatten process may be parallelized:
-// by placing proper locks, global cache pollution in go-openapi/spec may be avoided.
-func TestModelRace(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
-	initModelFixtures()
-
-	dassert := assert.New(t)
-
-	for i := 0; i < 10; i++ {
-		t.Logf("Iteration: %d", i)
-
-		for _, fixt := range testedModels {
-			fixture := fixt
-			if fixture.SpecFile == "" {
-				continue
-			}
-			fixtureSpec := fixture.SpecFile
-			runTitle := strings.Join([]string{"codegen", strings.TrimSuffix(path.Base(fixtureSpec), path.Ext(fixtureSpec))}, "-")
-			t.Run(runTitle, func(t *testing.T) {
-				t.Parallel()
-				log.SetOutput(ioutil.Discard)
-				for _, fixtureRun := range fixture.Runs {
-
-					// loads defines the start of the critical section because it comes with the global cache initialized
-					// TODO: should make this cache more manageable in go-openapi/spec
-					modelTestMutex.Lock()
-					specDoc, err := loads.Spec(fixtureSpec)
-					if !dassert.NoErrorf(err, "unexpected failure loading spec %s: %v", fixtureSpec, err) {
-						modelTestMutex.Unlock()
-						t.FailNow()
-						return
-					}
-					opts := fixtureRun.FixtureOpts
-					// this is the expanded or flattened spec
-					newSpecDoc, er0 := validateAndFlattenSpec(opts, specDoc)
-					if !dassert.NoErrorf(er0, "could not expand/flatten fixture %s: %v", fixtureSpec, er0) {
-						modelTestMutex.Unlock()
-						t.FailNow()
-						return
-					}
-					modelTestMutex.Unlock()
-					definitions := newSpecDoc.Spec().Definitions
-					for k := range fixtureRun.Definitions {
-						// pick definition to test
-						var schema *spec.Schema
-						for def, s := range definitions {
-							if strings.EqualFold(def, k) {
-								schema = &s
-								break
-							}
-						}
-						if !dassert.NotNil(schema, "expected to find definition %q in model fixture %s", k, fixtureSpec) {
-							t.FailNow()
-							return
-						}
-					}
-				}
-			})
-		}
-	}
+	// assert generated code (see fixture file)
+	fixtureExpectations.AssertModelCodegen(t, string(formatted), definitionName, fixtureSpec)
 }
-*/
diff --git a/generator/operation_test.go b/generator/operation_test.go
index 0ccedf18..2b7bba50 100644
--- a/generator/operation_test.go
+++ b/generator/operation_test.go
@@ -18,7 +18,6 @@ import (
 	"bytes"
 	"errors"
 	"io/ioutil"
-	"log"
 	"os"
 	"path/filepath"
 	"testing"
@@ -210,8 +209,7 @@ func TestMakeOperation(t *testing.T) {
 }
 
 func TestRenderOperation_InstagramSearch(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	b, err := methodPathOpBuilder("get", "/media/search", "../fixtures/codegen/instagram.yml")
 	require.NoError(t, err)
@@ -221,8 +219,8 @@ func TestRenderOperation_InstagramSearch(t *testing.T) {
 
 	buf := bytes.NewBuffer(nil)
 	opt := opts()
-	err = templates.MustGet("serverOperation").Execute(buf, gO)
-	require.NoError(t, err)
+
+	require.NoError(t, opt.templates.MustGet("serverOperation").Execute(buf, gO))
 
 	ff, err := opt.LanguageOpts.FormatContent("operation.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
@@ -237,8 +235,8 @@ func TestRenderOperation_InstagramSearch(t *testing.T) {
 	assertInCode(t, "models.Media", res)
 
 	buf = bytes.NewBuffer(nil)
-	err = templates.MustGet("serverResponses").Execute(buf, gO)
-	require.NoError(t, err)
+	require.NoError(t, opt.templates.MustGet("serverResponses").Execute(buf, gO))
+
 	ff, err = opt.LanguageOpts.FormatContent("response.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
 
@@ -255,8 +253,7 @@ func TestRenderOperation_InstagramSearch(t *testing.T) {
 
 	buf = bytes.NewBuffer(nil)
 	opt = opts()
-	err = templates.MustGet("serverOperation").Execute(buf, gO)
-	require.NoError(t, err)
+	require.NoError(t, opt.templates.MustGet("serverOperation").Execute(buf, gO))
 
 	ff, err = opt.LanguageOpts.FormatContent("operation.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
@@ -266,8 +263,7 @@ func TestRenderOperation_InstagramSearch(t *testing.T) {
 	assertNotInCode(t, "models", res)
 
 	buf = bytes.NewBuffer(nil)
-	err = templates.MustGet("serverResponses").Execute(buf, gO)
-	require.NoError(t, err)
+	require.NoError(t, opt.templates.MustGet("serverResponses").Execute(buf, gO))
 
 	ff, err = opt.LanguageOpts.FormatContent("operation.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
@@ -277,8 +273,7 @@ func TestRenderOperation_InstagramSearch(t *testing.T) {
 }
 
 func methodPathOpBuilder(method, path, fname string) (codeGenOpBuilder, error) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	if fname == "" {
 		fname = "../fixtures/codegen/todolist.simple.yml"
@@ -313,8 +308,7 @@ func methodPathOpBuilder(method, path, fname string) (codeGenOpBuilder, error) {
 
 // methodPathOpBuilderWithFlatten prepares an operation build based on method and path, with spec full flattening
 func methodPathOpBuilderWithFlatten(method, path, fname string) (codeGenOpBuilder, error) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	if fname == "" {
 		fname = "../fixtures/codegen/todolist.simple.yml"
@@ -350,8 +344,7 @@ func methodPathOpBuilderWithFlatten(method, path, fname string) (codeGenOpBuilde
 
 // opBuilderWithOpts prepares the making of an operation with spec flattening options
 func opBuilderWithOpts(name, fname string, o *GenOpts) (codeGenOpBuilder, error) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	if fname == "" {
 		// default fixture
@@ -461,17 +454,14 @@ func TestDateFormat_Spec1(t *testing.T) {
 	opts := opts()
 	opts.defaultsEnsured = false
 	opts.IsClient = true
-	err = opts.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, opts.EnsureDefaults())
 
-	err = templates.MustGet("clientParameter").Execute(buf, op)
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
 
 	ff, err := opts.LanguageOpts.FormatContent("put_testing.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
 
-	res := string(ff)
-	assertInCode(t, "frTestingThis.String()", res)
+	assertInCode(t, "frTestingThis.String()", string(ff))
 }
 
 func TestDateFormat_Spec2(t *testing.T) {
@@ -485,11 +475,9 @@ func TestDateFormat_Spec2(t *testing.T) {
 	opts := opts()
 	opts.defaultsEnsured = false
 	opts.IsClient = true
-	err = opts.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, opts.EnsureDefaults())
 
-	err = templates.MustGet("clientParameter").Execute(buf, op)
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
 
 	ff, err := opts.LanguageOpts.FormatContent("put_testing.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
@@ -499,10 +487,9 @@ func TestDateFormat_Spec2(t *testing.T) {
 }
 
 func TestBuilder_Issue1703(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, err := os.Getwd()
-	require.NoError(t, err)
+	defer discardOutput()()
+
+	dr := testCwd(t)
 
 	opts := &GenOpts{
 		Spec:              filepath.FromSlash("../fixtures/codegen/existing-model.yml"),
@@ -517,8 +504,7 @@ func TestBuilder_Issue1703(t *testing.T) {
 		ClientPackage:     "client",
 		Target:            dr,
 	}
-	err = opts.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, opts.EnsureDefaults())
 
 	appGen, err := newAppGenerator("x-go-type-import-bug", nil, nil, opts)
 	require.NoError(t, err)
@@ -528,21 +514,19 @@ func TestBuilder_Issue1703(t *testing.T) {
 
 	for _, o := range op.Operations {
 		buf := bytes.NewBuffer(nil)
-		err = templates.MustGet("serverResponses").Execute(buf, o)
-		require.NoError(t, err)
+		require.NoError(t, opts.templates.MustGet("serverResponses").Execute(buf, o))
 
 		ff, err := appGen.GenOpts.LanguageOpts.FormatContent("response.go", buf.Bytes())
 		require.NoErrorf(t, err, buf.String())
 
-		res := string(ff)
-		assertInCode(t, "jwk \"github.com/user/package\"", res)
+		assertInCode(t, "jwk \"github.com/user/package\"", string(ff))
 	}
 }
 
 func TestBuilder_Issue287(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	defer discardOutput()()
+
+	dr := testCwd(t)
 
 	opts := &GenOpts{
 		Spec:              filepath.FromSlash("../fixtures/bugs/287/swagger.yml"),
@@ -557,8 +541,7 @@ func TestBuilder_Issue287(t *testing.T) {
 		ClientPackage:     "client",
 		Target:            dr,
 	}
-	err := opts.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, opts.EnsureDefaults())
 
 	appGen, err := newAppGenerator("plainTexter", nil, nil, opts)
 	require.NoError(t, err)
@@ -567,20 +550,19 @@ func TestBuilder_Issue287(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("serverBuilder").Execute(buf, op)
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("serverBuilder").Execute(buf, op))
 
 	ff, err := appGen.GenOpts.LanguageOpts.FormatContent("put_testing.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
 
-	res := string(ff)
-	assertInCode(t, "case \"text/plain\":", res)
+	assertInCode(t, "case \"text/plain\":", string(ff))
 }
 
 func TestBuilder_Issue465(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	defer discardOutput()()
+
+	dr := testCwd(t)
+
 	opts := &GenOpts{
 		Spec:              filepath.FromSlash("../fixtures/bugs/465/swagger.yml"),
 		IncludeModel:      true,
@@ -595,8 +577,7 @@ func TestBuilder_Issue465(t *testing.T) {
 		Target:            dr,
 		IsClient:          true,
 	}
-	err := opts.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, opts.EnsureDefaults())
 
 	appGen, err := newAppGenerator("plainTexter", nil, nil, opts)
 	require.NoError(t, err)
@@ -605,20 +586,19 @@ func TestBuilder_Issue465(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("clientFacade").Execute(buf, op)
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("clientFacade").Execute(buf, op))
 
 	ff, err := appGen.GenOpts.LanguageOpts.FormatContent("put_testing.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
 
-	res := string(ff)
-	assertInCode(t, "/v1/fancyAPI", res)
+	assertInCode(t, "/v1/fancyAPI", string(ff))
 }
 
 func TestBuilder_Issue500(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	defer discardOutput()()
+
+	dr := testCwd(t)
+
 	opts := &GenOpts{
 		Spec:              filepath.FromSlash("../fixtures/bugs/500/swagger.yml"),
 		IncludeModel:      true,
@@ -632,8 +612,7 @@ func TestBuilder_Issue500(t *testing.T) {
 		ClientPackage:     "client",
 		Target:            dr,
 	}
-	err := opts.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, opts.EnsureDefaults())
 
 	appGen, err := newAppGenerator("multiTags", nil, nil, opts)
 	require.NoError(t, err)
@@ -642,8 +621,7 @@ func TestBuilder_Issue500(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("serverBuilder").Execute(buf, op)
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("serverBuilder").Execute(buf, op))
 
 	ff, err := appGen.GenOpts.LanguageOpts.FormatContent("put_testing.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
@@ -664,11 +642,9 @@ func TestGenClient_IllegalBOM(t *testing.T) {
 	opts := opts()
 	opts.defaultsEnsured = false
 	opts.IsClient = true
-	err = opts.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, opts.EnsureDefaults())
 
-	err = templates.MustGet("clientResponse").Execute(buf, op)
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("clientResponse").Execute(buf, op))
 }
 
 func TestGenClient_CustomFormatPath(t *testing.T) {
@@ -682,11 +658,9 @@ func TestGenClient_CustomFormatPath(t *testing.T) {
 	opts := opts()
 	opts.defaultsEnsured = false
 	opts.IsClient = true
-	err = opts.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, opts.EnsureDefaults())
 
-	err = templates.MustGet("clientParameter").Execute(buf, op)
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
 
 	assertInCode(t, `if err := r.SetPathParam("SeriesId", o.SeriesID.String()); err != nil`, buf.String())
 }
@@ -702,19 +676,18 @@ func TestGenClient_Issue733(t *testing.T) {
 	opts := opts()
 	opts.defaultsEnsured = false
 	opts.IsClient = true
-	err = opts.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, opts.EnsureDefaults())
 
-	err = templates.MustGet("clientResponse").Execute(buf, op)
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("clientResponse").Execute(buf, op))
 
 	assertInCode(t, "Labels []*int64 `json:\"labels\"`", buf.String())
 }
 
 func TestGenServerIssue890_ValidationTrueFlatteningTrue(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	defer discardOutput()()
+
+	dr := testCwd(t)
+
 	opts := &GenOpts{
 		Spec:              filepath.FromSlash("../fixtures/bugs/890/swagger.yaml"),
 		IncludeModel:      true,
@@ -732,8 +705,7 @@ func TestGenServerIssue890_ValidationTrueFlatteningTrue(t *testing.T) {
 	}
 
 	//Testing Server Generation
-	err := opts.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, opts.EnsureDefaults())
 
 	// Full flattening
 	opts.FlattenOpts.Expand = false
@@ -745,8 +717,7 @@ func TestGenServerIssue890_ValidationTrueFlatteningTrue(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("serverOperation").Execute(buf, op.Operations[0])
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("serverOperation").Execute(buf, op.Operations[0]))
 
 	filecontent, err := appGen.GenOpts.LanguageOpts.FormatContent("operation.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
@@ -756,25 +727,28 @@ func TestGenServerIssue890_ValidationTrueFlatteningTrue(t *testing.T) {
 }
 
 func TestGenClientIssue890_ValidationTrueFlatteningTrue(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
+	defer discardOutput()()
+
+	dr := testCwd(t)
 	defer func() {
-		log.SetOutput(os.Stdout)
-		dr, _ := os.Getwd()
 		_ = os.RemoveAll(filepath.Join(filepath.FromSlash(dr), "restapi"))
 	}()
+
 	opts := testGenOpts()
 	opts.Spec = "../fixtures/bugs/890/swagger.yaml"
 	opts.ValidateSpec = true
 	opts.FlattenOpts.Minimal = false
+
 	// Testing this is enough as there is only one operation which is specified as $ref.
 	// If this doesn't get resolved then there will be an error definitely.
-	assert.NoError(t, GenerateClient("foo", nil, nil, opts))
+	require.NoError(t, GenerateClient("foo", nil, nil, opts))
 }
 
 func TestGenServerIssue890_ValidationFalseFlattenTrue(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	defer discardOutput()()
+
+	dr := testCwd(t)
+
 	opts := &GenOpts{
 		Spec:              filepath.FromSlash("../fixtures/bugs/890/swagger.yaml"),
 		IncludeModel:      true,
@@ -791,8 +765,7 @@ func TestGenServerIssue890_ValidationFalseFlattenTrue(t *testing.T) {
 	}
 
 	//Testing Server Generation
-	err := opts.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, opts.EnsureDefaults())
 
 	// full flattening
 	opts.FlattenOpts.Minimal = false
@@ -803,7 +776,7 @@ func TestGenServerIssue890_ValidationFalseFlattenTrue(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	err = templates.MustGet("serverOperation").Execute(buf, op.Operations[0])
+	err = opts.templates.MustGet("serverOperation").Execute(buf, op.Operations[0])
 	require.NoError(t, err)
 
 	filecontent, err := appGen.GenOpts.LanguageOpts.FormatContent("operation.go", buf.Bytes())
@@ -814,12 +787,13 @@ func TestGenServerIssue890_ValidationFalseFlattenTrue(t *testing.T) {
 }
 
 func TestGenClientIssue890_ValidationFalseFlatteningTrue(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
+	defer discardOutput()()
+
+	dr := testCwd(t)
 	defer func() {
-		log.SetOutput(os.Stdout)
-		dr, _ := os.Getwd()
 		_ = os.RemoveAll(filepath.Join(filepath.FromSlash(dr), "restapi"))
 	}()
+
 	opts := testGenOpts()
 	opts.Spec = "../fixtures/bugs/890/swagger.yaml"
 	opts.ValidateSpec = false
@@ -831,9 +805,10 @@ func TestGenClientIssue890_ValidationFalseFlatteningTrue(t *testing.T) {
 }
 
 func TestGenServerIssue890_ValidationFalseFlattenFalse(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	defer discardOutput()()
+
+	dr := testCwd(t)
+
 	opts := &GenOpts{
 		Spec:              filepath.FromSlash("../fixtures/bugs/890/swagger.yaml"),
 		IncludeModel:      true,
@@ -850,23 +825,24 @@ func TestGenServerIssue890_ValidationFalseFlattenFalse(t *testing.T) {
 		IsClient:          true,
 	}
 
-	//Testing Server Generation
-	err := opts.EnsureDefaults()
+	// Testing Server Generation
+	require.NoError(t, opts.EnsureDefaults())
+
 	// minimal flattening
 	opts.FlattenOpts.Minimal = true
-	assert.NoError(t, err)
-	_, err = newAppGenerator("JsonRefOperation", nil, nil, opts)
+	_, err := newAppGenerator("JsonRefOperation", nil, nil, opts)
 	// if flatten is not set, expand takes over so this would resume normally
 	assert.NoError(t, err)
 }
 
 func TestGenClientIssue890_ValidationFalseFlattenFalse(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
+	defer discardOutput()()
+
+	dr := testCwd(t)
 	defer func() {
-		dr, _ := os.Getwd()
 		_ = os.RemoveAll(filepath.Join(filepath.FromSlash(dr), "restapi"))
-		log.SetOutput(os.Stdout)
 	}()
+
 	opts := testGenOpts()
 	opts.Spec = "../fixtures/bugs/890/swagger.yaml"
 	opts.ValidateSpec = false
@@ -879,9 +855,10 @@ func TestGenClientIssue890_ValidationFalseFlattenFalse(t *testing.T) {
 }
 
 func TestGenServerIssue890_ValidationTrueFlattenFalse(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	defer discardOutput()()
+
+	dr := testCwd(t)
+
 	opts := &GenOpts{
 		Spec:              filepath.FromSlash("../fixtures/bugs/890/swagger.yaml"),
 		IncludeModel:      true,
@@ -898,20 +875,21 @@ func TestGenServerIssue890_ValidationTrueFlattenFalse(t *testing.T) {
 		IsClient:          true,
 	}
 
-	//Testing Server Generation
-	err := opts.EnsureDefaults()
+	// Testing Server Generation
+	require.NoError(t, opts.EnsureDefaults())
+
 	// minimal flattening
 	opts.FlattenOpts.Minimal = true
-	assert.NoError(t, err)
-	_, err = newAppGenerator("JsonRefOperation", nil, nil, opts)
+
+	_, err := newAppGenerator("JsonRefOperation", nil, nil, opts)
 	// now if flatten is false, expand takes over so server generation should resume normally
 	assert.NoError(t, err)
 }
 
 func TestGenServerWithTemplate(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	defer discardOutput()()
+
+	dr := testCwd(t)
 
 	tests := []struct {
 		name      string
@@ -960,31 +938,36 @@ func TestGenServerWithTemplate(t *testing.T) {
 		},
 	}
 
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			//Testing Server Generation
-			err := tt.opts.EnsureDefaults()
-			require.NoError(t, err)
-
-			// minimal flattening
-			tt.opts.FlattenOpts.Minimal = true
-			_, err = newAppGenerator("JsonRefOperation", nil, nil, tt.opts)
-			if tt.wantError {
-				assert.Error(t, err)
-			} else {
-				assert.NoError(t, err)
-			}
-		})
-	}
+	t.Run("codegen operations", func(t *testing.T) {
+		for _, toPin := range tests {
+			tt := toPin
+			t.Run(tt.name, func(t *testing.T) {
+				t.Parallel()
+
+				// Testing Server Generation
+				require.NoError(t, tt.opts.EnsureDefaults())
+
+				// minimal flattening
+				tt.opts.FlattenOpts.Minimal = true
+				_, err := newAppGenerator("JsonRefOperation", nil, nil, tt.opts)
+				if tt.wantError {
+					require.Error(t, err)
+				} else {
+					require.NoError(t, err)
+				}
+			})
+		}
+	})
 }
 
 func TestGenClientIssue890_ValidationTrueFlattenFalse(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
+	defer discardOutput()()
+
+	dr := testCwd(t)
 	defer func() {
-		log.SetOutput(os.Stdout)
-		dr, _ := os.Getwd()
 		_ = os.RemoveAll(filepath.Join(filepath.FromSlash(dr), "restapi"))
 	}()
+
 	opts := testGenOpts()
 	opts.Spec = filepath.FromSlash("../fixtures/bugs/890/swagger.yaml")
 	opts.ValidateSpec = true
@@ -996,10 +979,11 @@ func TestGenClientIssue890_ValidationTrueFlattenFalse(t *testing.T) {
 
 // This tests that securityDefinitions generate stable code
 func TestBuilder_Issue1214(t *testing.T) {
+	defer discardOutput()()
+
+	dr := testCwd(t)
 	const any = `(.|\n)+`
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+
 	opts := &GenOpts{
 		Spec:              filepath.FromSlash("../fixtures/bugs/1214/fixture-1214.yaml"),
 		IncludeModel:      true,
@@ -1014,8 +998,7 @@ func TestBuilder_Issue1214(t *testing.T) {
 		Target:            dr,
 		IsClient:          false,
 	}
-	e := opts.EnsureDefaults()
-	require.NoError(t, e)
+	require.NoError(t, opts.EnsureDefaults())
 
 	appGen, e := newAppGenerator("fixture-1214", nil, nil, opts)
 	require.NoError(t, e)
@@ -1040,8 +1023,7 @@ func TestBuilder_Issue1214(t *testing.T) {
 			`api\.EAuth = func\(token string, scopes \[\]string\)`+any, res)
 
 		buf = bytes.NewBuffer(nil)
-		err = templates.MustGet("serverBuilder").Execute(buf, op)
-		require.NoError(t, err)
+		require.NoError(t, opts.templates.MustGet("serverBuilder").Execute(buf, op))
 
 		ff, err = appGen.GenOpts.LanguageOpts.FormatContent("fixture_1214_server.go", buf.Bytes())
 		require.NoErrorf(t, err, buf.String())
@@ -1169,8 +1151,8 @@ func TestGenSecurityRequirements(t *testing.T) {
 }
 
 func TestGenerateServerOperation(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
+
 	fname := "../fixtures/codegen/todolist.simple.yml"
 
 	tgt, _ := ioutil.TempDir(filepath.Dir(fname), "generated")
@@ -1187,32 +1169,26 @@ func TestGenerateServerOperation(t *testing.T) {
 		Spec:              fname,
 		Target:            tgt,
 	}
-	err := o.EnsureDefaults()
-	require.NoError(t, err)
+	require.NoError(t, o.EnsureDefaults())
 
-	err = GenerateServerOperation([]string{"createTask"}, nil)
-	assert.Error(t, err)
+	require.Error(t, GenerateServerOperation([]string{"createTask"}, nil))
 
 	d := o.TemplateDir
 	o.TemplateDir = "./nowhere"
-	err = GenerateServerOperation([]string{"notFound"}, o)
-	assert.Error(t, err)
+	require.Error(t, GenerateServerOperation([]string{"notFound"}, o))
 
 	o.TemplateDir = d
 	d = o.Spec
 	o.Spec = "nowhere.yaml"
-	err = GenerateServerOperation([]string{"notFound"}, o)
-	assert.Error(t, err)
-	o.Spec = d
+	require.Error(t, GenerateServerOperation([]string{"notFound"}, o))
 
-	err = GenerateServerOperation([]string{"notFound"}, o)
-	assert.Error(t, err)
+	o.Spec = d
+	require.Error(t, GenerateServerOperation([]string{"notFound"}, o))
 
-	err = GenerateServerOperation([]string{"createTask"}, o)
-	require.NoError(t, err)
+	require.NoError(t, GenerateServerOperation([]string{"createTask"}, o))
 
 	// check expected files are generated and that's it
-	_, err = os.Stat(filepath.Join(tgt, "tasks", "create_task.go"))
+	_, err := os.Stat(filepath.Join(tgt, "tasks", "create_task.go"))
 	assert.NoError(t, err)
 	_, err = os.Stat(filepath.Join(tgt, "tasks", "create_task_parameters.go"))
 	assert.NoError(t, err)
@@ -1234,9 +1210,10 @@ func TestGenerateServerOperation(t *testing.T) {
 
 // This tests that mimetypes generate stable code
 func TestBuilder_Issue1646(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	defer discardOutput()()
+
+	dr := testCwd(t)
+
 	opts := &GenOpts{
 		Spec:              filepath.FromSlash("../fixtures/bugs/1646/fixture-1646.yaml"),
 		IncludeModel:      true,
@@ -1273,9 +1250,10 @@ func TestBuilder_Issue1646(t *testing.T) {
 }
 
 func TestGenServer_StrictAdditionalProperties(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	defer discardOutput()()
+
+	dr := testCwd(t)
+
 	opts := &GenOpts{
 		Spec:              filepath.FromSlash("../fixtures/codegen/strict-additional-properties.yml"),
 		IncludeModel:      true,
@@ -1384,7 +1362,8 @@ func makeClientTimeoutNameTest() []struct {
 }
 
 func TestRenameTimeout(t *testing.T) {
-	for i, toPin := range makeClientTimeoutNameTest() {
+	for idx, toPin := range makeClientTimeoutNameTest() {
+		i := idx
 		testCase := toPin
 		t.Run(testCase.name, func(t *testing.T) {
 			t.Parallel()
@@ -1433,28 +1412,32 @@ func TestDeconflictTag(t *testing.T) {
 }
 
 func TestGenServer_2161_panic(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	t.Parallel()
+	defer discardOutput()()
+
+	generated, err := ioutil.TempDir(testCwd(t), "generated_2161")
+	require.NoError(t, err)
+
+	defer func() {
+		_ = os.RemoveAll(generated)
+	}()
+
 	opts := &GenOpts{
-		Spec:              filepath.FromSlash("../fixtures/bugs/2161/fixture-2161-panic.json"),
-		IncludeModel:      true,
-		IncludeHandler:    true,
-		IncludeParameters: true,
-		IncludeResponses:  true,
-		IncludeMain:       true,
-		APIPackage:        "restapi",
-		ModelPackage:      "model",
-		ServerPackage:     "server",
-		ClientPackage:     "client",
-		Target:            dr,
-		IsClient:          false,
-	}
-	if err := opts.EnsureDefaults(); err != nil {
-		panic(err)
+		Spec:                       filepath.FromSlash("../fixtures/bugs/2161/fixture-2161-panic.json"),
+		IncludeModel:               true,
+		IncludeHandler:             true,
+		IncludeParameters:          true,
+		IncludeResponses:           true,
+		IncludeMain:                true,
+		APIPackage:                 "restapi",
+		ModelPackage:               "model",
+		ServerPackage:              "server",
+		ClientPackage:              "client",
+		Target:                     generated,
+		IsClient:                   false,
+		StrictAdditionalProperties: true,
 	}
-
-	opts.StrictAdditionalProperties = true
+	require.NoError(t, opts.EnsureDefaults())
 
 	appGen, err := newAppGenerator("inlinedSubtype", nil, nil, opts)
 	require.NoError(t, err)
@@ -1471,8 +1454,7 @@ func TestGenServer_2161_panic(t *testing.T) {
 	}
 	require.NotEmpty(t, selectedOp, "dev error: invalid test vs fixture")
 
-	err = templates.MustGet("serverOperation").Execute(buf, op.Operations[selectedOp])
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("serverOperation").Execute(buf, op.Operations[selectedOp]))
 
 	_, err = appGen.GenOpts.LanguageOpts.FormatContent(op.Operations[selectedOp].Name+".go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
@@ -1481,9 +1463,9 @@ func TestGenServer_2161_panic(t *testing.T) {
 }
 
 func TestGenServer_1659_Principal(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
-	dr, _ := os.Getwd()
+	defer discardOutput()()
+
+	dr := testCwd(t)
 
 	for _, toPin := range []struct {
 		Title       string
@@ -1750,6 +1732,8 @@ func TestGenServer_1659_Principal(t *testing.T) {
 	} {
 		fixture := toPin
 		t.Run(fixture.Title, func(t *testing.T) {
+			t.Parallel()
+
 			opts := fixture.Opts
 			require.NoError(t, opts.EnsureDefaults())
 			require.NoError(t, opts.setTemplates())
@@ -1761,10 +1745,11 @@ func TestGenServer_1659_Principal(t *testing.T) {
 			require.NoError(t, err)
 
 			bufC := bytes.NewBuffer(nil)
-			require.NoError(t, templates.MustGet("serverConfigureapi").Execute(bufC, op))
+			require.NoError(t, opts.templates.MustGet("serverConfigureapi").Execute(bufC, op))
 
 			_, err = appGen.GenOpts.LanguageOpts.FormatContent("configure_api.go", bufC.Bytes())
 			require.NoErrorf(t, err, bufC.String())
+
 			for _, line := range fixture.Expected["configure"] {
 				assertInCode(t, line, bufC.String())
 			}
@@ -1774,7 +1759,7 @@ func TestGenServer_1659_Principal(t *testing.T) {
 
 			for i := range op.Operations {
 				bufO := bytes.NewBuffer(nil)
-				require.NoError(t, templates.MustGet("serverOperation").Execute(bufO, op.Operations[i]))
+				require.NoError(t, opts.templates.MustGet("serverOperation").Execute(bufO, op.Operations[i]))
 
 				_, erf := appGen.GenOpts.LanguageOpts.FormatContent(op.Operations[i].Name+".go", bufO.Bytes())
 				require.NoErrorf(t, erf, bufO.String())
diff --git a/generator/parameter_test.go b/generator/parameter_test.go
index 547b05bf..97ad1a9e 100644
--- a/generator/parameter_test.go
+++ b/generator/parameter_test.go
@@ -17,9 +17,6 @@ package generator
 import (
 	"bytes"
 	"fmt"
-	"io/ioutil"
-	"log"
-	"os"
 	"path"
 	"path/filepath"
 	"strings"
@@ -44,6 +41,7 @@ func TestBodyParams(t *testing.T) {
 	for k := range b.Doc.Spec().Definitions {
 		resolver.KnownDefs[k] = struct{}{}
 	}
+
 	for _, param := range op.Parameters {
 		if param.Name == "body" {
 			gp, perr := b.MakeParameter("a", resolver, param, nil)
@@ -62,27 +60,32 @@ func TestBodyParams(t *testing.T) {
 	_, _, op, ok = b.Analyzed.OperationForName("createTask")
 	require.True(t, ok)
 	require.NotNil(t, op)
+
 	resolver = &typeResolver{ModelsPackage: b.ModelsPackage, Doc: b.Doc}
 	resolver.KnownDefs = make(map[string]struct{})
+
 	for k := range b.Doc.Spec().Definitions {
 		resolver.KnownDefs[k] = struct{}{}
 	}
-	for _, param := range op.Parameters {
-		if param.Name == "body" {
-			gp, err := b.MakeParameter("a", resolver, param, nil)
-			require.NoError(t, err)
-			assert.True(t, gp.IsBodyParam())
-			require.NotNil(t, gp.Schema)
-			assert.True(t, gp.Schema.IsComplexObject)
-			assert.False(t, gp.Schema.IsAnonymous)
-			assert.Equal(t, "CreateTaskBody", gp.Schema.GoType)
 
-			gpe, ok := b.ExtraSchemas["CreateTaskBody"]
-			assert.True(t, ok)
-			assert.True(t, gpe.IsComplexObject)
-			assert.False(t, gpe.IsAnonymous)
-			assert.Equal(t, "CreateTaskBody", gpe.GoType)
+	for _, param := range op.Parameters {
+		if param.Name != "body" {
+			continue
 		}
+
+		gp, err := b.MakeParameter("a", resolver, param, nil)
+		require.NoError(t, err)
+		assert.True(t, gp.IsBodyParam())
+		require.NotNil(t, gp.Schema)
+		assert.True(t, gp.Schema.IsComplexObject)
+		assert.False(t, gp.Schema.IsAnonymous)
+		assert.Equal(t, "CreateTaskBody", gp.Schema.GoType)
+
+		gpe, ok := b.ExtraSchemas["CreateTaskBody"]
+		assert.True(t, ok)
+		assert.True(t, gpe.IsComplexObject)
+		assert.False(t, gpe.IsAnonymous)
+		assert.Equal(t, "CreateTaskBody", gpe.GoType)
 	}
 }
 
@@ -232,25 +235,34 @@ type paramTestContext struct {
 	Items     *paramItemsTestContext
 }
 
-func (ctx *paramTestContext) assertParameter(t testing.TB) bool {
+func (ctx *paramTestContext) assertParameter(t testing.TB) (result bool) {
+	defer func() {
+		result = !t.Failed()
+	}()
+
 	_, _, op, err := ctx.B.Analyzed.OperationForName(ctx.OpID)
-	if assert.True(t, err) && assert.NotNil(t, op) {
-		resolver := &typeResolver{ModelsPackage: ctx.B.ModelsPackage, Doc: ctx.B.Doc}
-		resolver.KnownDefs = make(map[string]struct{})
-		for k := range ctx.B.Doc.Spec().Definitions {
-			resolver.KnownDefs[k] = struct{}{}
-		}
-		for _, param := range op.Parameters {
-			if param.Name == ctx.Name {
-				gp, err := ctx.B.MakeParameter("a", resolver, param, nil)
-				if assert.NoError(t, err) {
-					return assert.True(t, ctx.assertGenParam(t, param, gp))
-				}
-			}
+
+	require.True(t, err)
+	require.NotNil(t, op)
+
+	resolver := &typeResolver{ModelsPackage: ctx.B.ModelsPackage, Doc: ctx.B.Doc}
+	resolver.KnownDefs = make(map[string]struct{})
+
+	for k := range ctx.B.Doc.Spec().Definitions {
+		resolver.KnownDefs[k] = struct{}{}
+	}
+	for _, param := range op.Parameters {
+		if param.Name != ctx.Name {
+			continue
 		}
-		return false
+
+		gp, err := ctx.B.MakeParameter("a", resolver, param, nil)
+		require.NoError(t, err)
+
+		assert.True(t, ctx.assertGenParam(t, param, gp))
 	}
-	return false
+
+	return
 }
 
 func (ctx *paramTestContext) assertGenParam(t testing.TB, param spec.Parameter, gp GenParameter) bool {
@@ -420,13 +432,11 @@ var bug163Properties = []paramTestContext{
 }
 
 func TestGenParameters_Simple(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
 
 	b, err := opBuilder("getSearch", "../fixtures/bugs/163/swagger.yml")
 	require.NoError(t, err)
+
 	for _, v := range bug163Properties {
 		v.B = b
 		require.True(t, v.assertParameter(t))
@@ -434,48 +444,41 @@ func TestGenParameters_Simple(t *testing.T) {
 }
 
 func TestGenParameter_Enhancement936(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
 
 	b, err := opBuilder("find", "../fixtures/enhancements/936/fixture-936.yml")
 	require.NoError(t, err)
+
 	op, err := b.MakeOperation()
 	require.NoError(t, err)
+
 	buf := bytes.NewBuffer(nil)
 	opts := opts()
-	err = templates.MustGet("serverParameter").Execute(buf, op)
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
 	ff, err := opts.LanguageOpts.FormatContent("find_parameters.go", buf.Bytes())
-	if err != nil {
-		fmt.Println(buf.String())
-	}
-	require.NoError(t, err)
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
 	res := string(ff)
 	assertInCode(t, "ctx := validate.WithOperationRequest(context.Background())", res)
 	assertInCode(t, "if err := body.ContextValidate(ctx, route.Formats)", res)
 }
 
 func TestGenParameter_Issue163(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
 
 	b, err := opBuilder("getSearch", "../fixtures/bugs/163/swagger.yml")
 	require.NoError(t, err)
 	op, err := b.MakeOperation()
 	require.NoError(t, err)
+
 	buf := bytes.NewBuffer(nil)
 	opts := opts()
-	err = templates.MustGet("serverParameter").Execute(buf, op)
-	require.NoError(t, err)
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
 	ff, err := opts.LanguageOpts.FormatContent("get_search_parameters.go", buf.Bytes())
-	if err != nil {
-		fmt.Println(buf.String())
-	}
-	require.NoError(t, err)
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
 	res := string(ff)
 	// NOTE(fredbi): removed default values resolution from private details (defaults are resolved in NewXXXParams())
 	assertInCode(t, "stringTypeInQueryDefault = string(\"qsValue\")", res)
@@ -483,55 +486,40 @@ func TestGenParameter_Issue163(t *testing.T) {
 }
 
 func TestGenParameter_Issue195(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
 
 	b, err := opBuilder("getTesting", "../fixtures/bugs/195/swagger.json")
-	if assert.NoError(t, err) {
-		op, err := b.MakeOperation()
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("get_testing.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertInCode(t, "TestingThis *int64", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := b.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("get_testing.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, "TestingThis *int64", string(ff))
 }
 
 func TestGenParameter_Issue196(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
 
 	b, err := opBuilder("postEvents", "../fixtures/bugs/196/swagger.yml")
-	if assert.NoError(t, err) {
-		op, err := b.MakeOperation()
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_events.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertInCode(t, "body.Validate", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := b.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+	ff, err := opts.LanguageOpts.FormatContent("post_events.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, "body.Validate", string(ff))
 }
 
 func TestGenParameter_Issue217(t *testing.T) {
@@ -545,65 +533,53 @@ func TestGenParameter_Issue217(t *testing.T) {
 
 func assertNoValidator(t testing.TB, opName, path string) {
 	b, err := opBuilder(opName, path)
-	if assert.NoError(t, err) {
-		op, err := b.MakeOperation()
-		if assert.NoError(t, err) {
-			var buf bytes.Buffer
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(&buf, op)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_echo.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertNotInCode(t, "body.Validate", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := b.MakeOperation()
+	require.NoError(t, err)
+
+	var buf bytes.Buffer
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(&buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_echo.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertNotInCode(t, "body.Validate", string(ff))
 }
 
 func TestGenParameter_Issue249(t *testing.T) {
 	b, err := opBuilder("putTesting", "../fixtures/bugs/249/swagger.json")
-	if assert.NoError(t, err) {
-		op, err := b.MakeOperation()
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("put_testing.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertNotInCode(t, "valuesTestingThis := o.TestingThis", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := b.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("put_testing.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertNotInCode(t, "valuesTestingThis := o.TestingThis", string(ff))
 }
 
 func TestGenParameter_Issue248(t *testing.T) {
 	b, err := opBuilder("CreateThing", "../fixtures/bugs/248/swagger.json")
-	if assert.NoError(t, err) {
-		op, err := b.MakeOperation()
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("create_thing.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertInCode(t, ", *o.OptionalQueryEnum", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := b.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("create_thing.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, ", *o.OptionalQueryEnum", string(ff))
 }
 
 func TestGenParameter_Issue303(t *testing.T) {
@@ -618,666 +594,573 @@ func TestGenParameter_Issue303(t *testing.T) {
 		},
 	}
 
-	for service, codelines := range services {
-		gen, err := opBuilder(service, "../fixtures/enhancements/303/swagger.yml")
-		if assert.NoError(t, err) {
+	for k, toPin := range services {
+		service := k
+		codelines := toPin
+
+		t.Run(fmt.Sprintf("%s-%s", t.Name(), service), func(t *testing.T) {
+			t.Parallel()
+
+			gen, err := opBuilder(service, "../fixtures/enhancements/303/swagger.yml")
+			require.NoError(t, err)
+
 			op, err := gen.MakeOperation()
-			if assert.NoError(t, err) {
-				param := op.Params[0]
-				assert.Equal(t, "fruit", param.Name)
-				assert.True(t, param.IsEnumCI)
-				extension := param.Extensions["x-go-enum-ci"]
-				assert.NotNil(t, extension)
-				xGoEnumCI, ok := extension.(bool)
-				assert.True(t, ok)
-				assert.True(t, xGoEnumCI)
+			require.NoError(t, err)
 
-				buf := bytes.NewBuffer(nil)
-				err = templates.MustGet("serverParameter").Execute(buf, op)
-				if assert.NoError(t, err) {
-					opts := opts()
-					ff, err := opts.LanguageOpts.FormatContent("case_insensitive_enum_parameter.go", buf.Bytes())
-					if assert.NoError(t, err) {
-						res := string(ff)
-						for _, codeline := range codelines {
-							assertInCode(t, codeline, res)
-						}
-					} else {
-						fmt.Println(buf.String())
-					}
-				}
+			param := op.Params[0]
+			assert.Equal(t, "fruit", param.Name)
+			assert.True(t, param.IsEnumCI)
+
+			extension := param.Extensions["x-go-enum-ci"]
+			assert.NotNil(t, extension)
+
+			xGoEnumCI, ok := extension.(bool)
+			assert.True(t, ok)
+			assert.True(t, xGoEnumCI)
+
+			buf := bytes.NewBuffer(nil)
+			opts := opts()
+			require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+			ff, err := opts.LanguageOpts.FormatContent("case_insensitive_enum_parameter.go", buf.Bytes())
+			require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+			res := string(ff)
+			for _, codeline := range codelines {
+				assertInCode(t, codeline, res)
 			}
-		}
+		})
 	}
 }
 
 func TestGenParameter_Issue350(t *testing.T) {
 	b, err := opBuilder("withBoolDefault", "../fixtures/codegen/todolist.allparams.yml")
-	if assert.NoError(t, err) {
-		op, err := b.MakeOperation()
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("with_bool_default.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertInCode(t, "Verbose: &verboseDefault", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := b.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("with_bool_default.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	res := string(ff)
+	assertInCode(t, "Verbose: &verboseDefault", res)
 }
 
 func TestGenParameter_Issue351(t *testing.T) {
 	b, err := opBuilder("withArray", "../fixtures/codegen/todolist.allparams.yml")
-	if assert.NoError(t, err) {
-		op, err := b.MakeOperation()
-		if assert.NoError(t, err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(t, err) {
-				ff, err := opts.LanguageOpts.FormatContent("with_array.go", buf.Bytes())
-				if assert.NoError(t, err) {
-					res := string(ff)
-					assertInCode(t, "validate.MinLength(fmt.Sprintf(\"%s.%v\", \"sha256\", i), \"query\", sha256I, 64)", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := b.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("with_array.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	res := string(ff)
+	assertInCode(t, "validate.MinLength(fmt.Sprintf(\"%s.%v\", \"sha256\", i), \"query\", sha256I, 64)", res)
 }
 
 func TestGenParameter_Issue511(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := opBuilder("postModels", "../fixtures/bugs/511/swagger.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertNotInCode(t, "fds := runtime.Values(r.Form)", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	res := string(ff)
+	assertNotInCode(t, "fds := runtime.Values(r.Form)", res)
 }
 
 func TestGenParameter_Issue628_Collection(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := opBuilder("collection", "../fixtures/bugs/628/swagger.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, `value, err := formats.Parse("uuid", workspaceIDIV)`, res) // NOTE(fredbi): added type assertion
-					assertInCode(t, `workspaceIDI := *(value.(*strfmt.UUID))`, res)
-					assertInCode(t, `workspaceIDIR = append(workspaceIDIR, workspaceIDI)`, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	res := string(ff)
+	assertInCode(t, `value, err := formats.Parse("uuid", workspaceIDIV)`, res) // NOTE(fredbi): added type assertion
+	assertInCode(t, `workspaceIDI := *(value.(*strfmt.UUID))`, res)
+	assertInCode(t, `workspaceIDIR = append(workspaceIDIR, workspaceIDI)`, res)
 }
 
 func TestGenParameter_Issue628_Single(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := opBuilder("single", "../fixtures/bugs/628/swagger.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, `value, err := formats.Parse("uuid", raw)`, res)
-					assertInCode(t, `o.WorkspaceID = *(value.(*strfmt.UUID))`, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	res := string(ff)
+	assertInCode(t, `value, err := formats.Parse("uuid", raw)`, res)
+	assertInCode(t, `o.WorkspaceID = *(value.(*strfmt.UUID))`, res)
 }
 
 func TestGenParameter_Issue628_Details(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := opBuilder("details", "../fixtures/bugs/628/swagger.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, `value, err := formats.Parse("uuid", raw)`, res)
-					assertInCode(t, `o.ID = *(value.(*strfmt.UUID))`, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	res := string(ff)
+	assertInCode(t, `value, err := formats.Parse("uuid", raw)`, res)
+	assertInCode(t, `o.ID = *(value.(*strfmt.UUID))`, res)
 }
 
 func TestGenParameter_Issue731_Collection(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := opBuilder("collection", "../fixtures/bugs/628/swagger.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, `for _, v := range o.WorkspaceID`, res)
-					assertInCode(t, `valuesWorkspaceID = append(valuesWorkspaceID, v.String())`, res)
-					assertInCode(t, `joinedWorkspaceID := swag.JoinByFormat(valuesWorkspaceID, "")`, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	res := string(ff)
+	assertInCode(t, `for _, v := range o.WorkspaceID`, res)
+	assertInCode(t, `valuesWorkspaceID = append(valuesWorkspaceID, v.String())`, res)
+	assertInCode(t, `joinedWorkspaceID := swag.JoinByFormat(valuesWorkspaceID, "")`, res)
 }
 
 func TestGenParameter_Issue731_Single(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := opBuilder("single", "../fixtures/bugs/628/swagger.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, `qWorkspaceID := qrWorkspaceID.String()`, res)
-					assertInCode(t, `r.SetQueryParam("workspace_id", qWorkspaceID)`, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	res := string(ff)
+	assertInCode(t, `qWorkspaceID := qrWorkspaceID.String()`, res)
+	assertInCode(t, `r.SetQueryParam("workspace_id", qWorkspaceID)`, res)
 }
 
 func TestGenParameter_Issue731_Details(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := opBuilder("details", "../fixtures/bugs/628/swagger.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, `r.SetPathParam("id", o.ID.String())`, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, `r.SetPathParam("id", o.ID.String())`, string(ff))
 }
 
 func TestGenParameter_Issue809_Client(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := methodPathOpBuilder("get", "/foo", "../fixtures/bugs/809/swagger.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, "valuesGroups", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, "valuesGroups", string(ff))
 }
 
 func TestGenParameter_Issue809_Server(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := methodPathOpBuilder("get", "/foo", "../fixtures/bugs/809/swagger.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, "groupsIC := rawData", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, "groupsIC := rawData", string(ff))
 }
 
 func TestGenParameter_Issue1010_Server(t *testing.T) {
-	assert := assert.New(t)
+	gen, err := methodPathOpBuilder("get", "/widgets/", "../fixtures/bugs/1010/swagger.yml")
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("get_widgets.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
 
-	gen, err := methodPathOpBuilder("get", "/widgets/", "../fixtures/bugs/1010/swagger.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("get_widgets.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, "validate.Pattern(fmt.Sprintf(\"%s.%v\", \"category_id\", i), \"query\", categoryIDI, `^[0-9abcdefghjkmnpqrtuvwxyz]{29}$`)", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	assertInCode(t, "validate.Pattern(fmt.Sprintf(\"%s.%v\", \"category_id\", i), \"query\", categoryIDI, `^[0-9abcdefghjkmnpqrtuvwxyz]{29}$`)", string(ff))
 }
 
 func TestGenParameter_Issue710(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
-
-	assert := assert.New(t)
+	defer discardOutput()()
 
 	gen, err := opBuilder("createTask", "../fixtures/codegen/todolist.allparams.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("create_task_parameter.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, "(typeVar", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("create_task_parameter.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, "(typeVar", string(ff))
 }
 
 func TestGenParameter_Issue776_LocalFileRef(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
+
 	b, err := opBuilderWithFlatten("GetItem", "../fixtures/bugs/776/param.yaml")
 	require.NoError(t, err)
+
 	op, err := b.MakeOperation()
 	require.NoError(t, err)
+
 	var buf bytes.Buffer
 	opts := opts()
-	require.NoError(t, templates.MustGet("serverParameter").Execute(&buf, op))
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(&buf, op))
 	ff, err := opts.LanguageOpts.FormatContent("do_empty_responses.go", buf.Bytes())
-	if err != nil {
-		fmt.Println(buf.String())
-	}
-	require.NoError(t, err)
-	assertInCode(t, "Body *models.Item", string(ff))
-	assertNotInCode(t, "type GetItemParamsBody struct", string(ff))
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	res := string(ff)
+	assertInCode(t, "Body *models.Item", res)
+	assertNotInCode(t, "type GetItemParamsBody struct", res)
 
 }
 
 func TestGenParameter_Issue1111(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := opBuilder("start-es-cluster-instances", "../fixtures/bugs/1111/arrayParam.json")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_clusters_elasticsearch_cluster_id_instances_instance_ids_start_parameters.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, `r.SetPathParam("instance_ids", joinedInstanceIds[0])`, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_clusters_elasticsearch_cluster_id_instances_instance_ids_start_parameters.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, `r.SetPathParam("instance_ids", joinedInstanceIds[0])`, string(ff))
 }
 
 func TestGenParameter_Issue1462(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := opBuilder("start-es-cluster-instances", "../fixtures/bugs/1462/arrayParam.json")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_clusters_elasticsearch_cluster_id_instances_instance_ids_start_parameters.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, `if len(joinedInstanceIds) > 0 {`, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_clusters_elasticsearch_cluster_id_instances_instance_ids_start_parameters.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, `if len(joinedInstanceIds) > 0 {`, string(ff))
 }
 
 func TestGenParameter_Issue1199(t *testing.T) {
-	assert := assert.New(t)
 	var assertion = `if o.Body != nil {
 		if err := r.SetBodyParam(o.Body); err != nil {
 			return err
 		}
 	}`
+
 	gen, err := opBuilder("move-clusters", "../fixtures/bugs/1199/nonEmptyBody.json")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("move_clusters_parameters.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, assertion, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("move_clusters_parameters.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, assertion, string(ff))
 }
 
 func TestGenParameter_Issue1325(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
-
-	assert := assert.New(t)
+	defer discardOutput()()
 
 	gen, err := opBuilder("uploadFile", "../fixtures/bugs/1325/swagger.yaml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("create_task_parameter.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, "runtime.NamedReadCloser", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("create_task_parameter.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, "runtime.NamedReadCloser", string(ff))
 }
 
 func TestGenParameter_ArrayQueryParameters(t *testing.T) {
-	assert := assert.New(t)
-
 	gen, err := opBuilder("arrayQueryParams", "../fixtures/codegen/todolist.arrayquery.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("array_query_params.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, `siBoolIC := swag.SplitByFormat(qvSiBool, "ssv")`, res)
-					assertInCode(t, `var siBoolIR []bool`, res)
-					assertInCode(t, `for i, siBoolIV := range siBoolIC`, res)
-					assertInCode(t, `siBoolI, err := swag.ConvertBool(siBoolIV)`, res)
-					assertInCode(t, `siBoolIR = append(siBoolIR, siBoolI)`, res)
-					assertInCode(t, `o.SiBool = siBoolIR`, res)
-					assertInCode(t, `siBoolSize := int64(len(o.SiBool))`, res)
-					assertInCode(t, `err := validate.MinItems("siBool", "query", siBoolSize, 5)`, res)
-					assertInCode(t, `err := validate.MaxItems("siBool", "query", siBoolSize, 50)`, res)
-
-					assertInCode(t, `siFloatIC := rawData`, res)
-					assertInCode(t, `var siFloatIR []float64`, res)
-					assertInCode(t, `for i, siFloatIV := range siFloatIC`, res)
-					assertInCode(t, `siFloatI, err := swag.ConvertFloat64(siFloatIV)`, res)
-					assertInCode(t, `return errors.InvalidType(fmt.Sprintf("%s.%v", "siFloat", i), "query", "float64", siFloatI)`, res)
-					assertInCode(t, `err := validate.Minimum(fmt.Sprintf("%s.%v", "siFloat", i), "query", float64(siFloatI), 3, true)`, res)
-					assertInCode(t, `err := validate.Maximum(fmt.Sprintf("%s.%v", "siFloat", i), "query", float64(siFloatI), 100, true); err != nil`, res)
-					assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siFloat", i), "query", float64(siFloatI), 1.5)`, res)
-					assertInCode(t, `siFloatIR = append(siFloatIR, siFloatI)`, res)
-					assertInCode(t, `o.SiFloat = siFloatIR`, res)
-					assertInCode(t, `siFloatSize := int64(len(o.SiFloat))`, res)
-					assertInCode(t, `err := validate.MinItems("siFloat", "query", siFloatSize, 5)`, res)
-					assertInCode(t, `err := validate.MaxItems("siFloat", "query", siFloatSize, 50)`, res)
-
-					assertInCode(t, `siFloat32IC := swag.SplitByFormat(qvSiFloat32, "")`, res)
-					assertInCode(t, `var siFloat32IR []float32`, res)
-					assertInCode(t, `for i, siFloat32IV := range siFloat32IC`, res)
-					assertInCode(t, `siFloat32I, err := swag.ConvertFloat32(siFloat32IV)`, res)
-					assertInCode(t, `err := validate.Minimum(fmt.Sprintf("%s.%v", "siFloat32", i), "query", float64(siFloat32I), 3, true)`, res)
-					assertInCode(t, `err := validate.Maximum(fmt.Sprintf("%s.%v", "siFloat32", i), "query", float64(siFloat32I), 100, true)`, res)
-					assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siFloat32", i), "query", float64(siFloat32I), 1.5)`, res)
-					assertInCode(t, `siFloat32IR = append(siFloat32IR, siFloat32I)`, res)
-					assertInCode(t, `o.SiFloat32 = siFloat32IR`, res)
-
-					assertInCode(t, `siFloat64IC := swag.SplitByFormat(qvSiFloat64, "pipes")`, res)
-					assertInCode(t, `var siFloat64IR []float64`, res)
-					assertInCode(t, `for i, siFloat64IV := range siFloat64IC`, res)
-					assertInCode(t, `siFloat64I, err := swag.ConvertFloat64(siFloat64IV)`, res)
-					assertInCode(t, `err := validate.Minimum(fmt.Sprintf("%s.%v", "siFloat64", i), "query", float64(siFloat64I), 3, true)`, res)
-					assertInCode(t, `err := validate.Maximum(fmt.Sprintf("%s.%v", "siFloat64", i), "query", float64(siFloat64I), 100, true)`, res)
-					assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siFloat64", i), "query", float64(siFloat64I), 1.5)`, res)
-					assertInCode(t, `siFloat64IR = append(siFloat64IR, siFloat64I)`, res)
-					assertInCode(t, `o.SiFloat64 = siFloat64IR`, res)
-					assertInCode(t, `siFloat64Size := int64(len(o.SiFloat64))`, res)
-					assertInCode(t, `err := validate.MinItems("siFloat64", "query", siFloat64Size, 5)`, res)
-					assertInCode(t, `err := validate.MaxItems("siFloat64", "query", siFloat64Size, 50)`, res)
-
-					assertInCode(t, `siIntIC := swag.SplitByFormat(qvSiInt, "pipes")`, res)
-					assertInCode(t, `var siIntIR []int64`, res)
-					assertInCode(t, `for i, siIntIV := range siIntIC`, res)
-					assertInCode(t, `siIntI, err := swag.ConvertInt64(siIntIV)`, res)
-					assertInCode(t, `err := validate.MinimumInt(fmt.Sprintf("%s.%v", "siInt", i), "query", int64(siIntI), 8, true)`, res)
-					assertInCode(t, `err := validate.MaximumInt(fmt.Sprintf("%s.%v", "siInt", i), "query", int64(siIntI), 100, true)`, res)
-					assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siInt", i), "query", float64(siIntI), 2)`, res)
-					assertInCode(t, `siIntIR = append(siIntIR, siIntI)`, res)
-					assertInCode(t, `o.SiInt = siIntIR`, res)
-					assertInCode(t, `siIntSize := int64(len(o.SiInt))`, res)
-					assertInCode(t, `err := validate.MinItems("siInt", "query", siIntSize, 5)`, res)
-					assertInCode(t, `err := validate.MaxItems("siInt", "query", siIntSize, 50)`, res)
-
-					assertInCode(t, `siInt32IC := swag.SplitByFormat(qvSiInt32, "tsv")`, res)
-					assertInCode(t, `var siInt32IR []int32`, res)
-					assertInCode(t, `for i, siInt32IV := range siInt32IC`, res)
-					assertInCode(t, `siInt32I, err := swag.ConvertInt32(siInt32IV)`, res)
-					assertInCode(t, `err := validate.MinimumInt(fmt.Sprintf("%s.%v", "siInt32", i), "query", int64(siInt32I), 8, true)`, res)
-					assertInCode(t, `err := validate.MaximumInt(fmt.Sprintf("%s.%v", "siInt32", i), "query", int64(siInt32I), 100, true)`, res)
-					assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siInt32", i), "query", float64(siInt32I), 2)`, res)
-					assertInCode(t, `siInt32IR = append(siInt32IR, siInt32I)`, res)
-					assertInCode(t, `o.SiInt32 = siInt32IR`, res)
-					assertInCode(t, `siFloat32Size := int64(len(o.SiFloat32))`, res)
-					assertInCode(t, `err := validate.MinItems("siFloat32", "query", siFloat32Size, 5)`, res)
-					assertInCode(t, `err := validate.MaxItems("siFloat32", "query", siFloat32Size, 50)`, res)
-					assertInCode(t, `siInt32Size := int64(len(o.SiInt32))`, res)
-					assertInCode(t, `err := validate.MinItems("siInt32", "query", siInt32Size, 5)`, res)
-					assertInCode(t, `err := validate.MaxItems("siInt32", "query", siInt32Size, 50)`, res)
-
-					assertInCode(t, `siInt64IC := swag.SplitByFormat(qvSiInt64, "ssv")`, res)
-					assertInCode(t, `var siInt64IR []int64`, res)
-					assertInCode(t, `for i, siInt64IV := range siInt64IC`, res)
-					assertInCode(t, `siInt64I, err := swag.ConvertInt64(siInt64IV)`, res)
-					assertInCode(t, `err := validate.MinimumInt(fmt.Sprintf("%s.%v", "siInt64", i), "query", int64(siInt64I), 8, true)`, res)
-					assertInCode(t, `err := validate.MaximumInt(fmt.Sprintf("%s.%v", "siInt64", i), "query", int64(siInt64I), 100, true)`, res)
-					assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siInt64", i), "query", float64(siInt64I), 2)`, res)
-					assertInCode(t, `siInt64IR = append(siInt64IR, siInt64I)`, res)
-					assertInCode(t, `o.SiInt64 = siInt64IR`, res)
-					assertInCode(t, `siInt64Size := int64(len(o.SiInt64))`, res)
-					assertInCode(t, `err := validate.MinItems("siInt64", "query", siInt64Size, 5)`, res)
-					assertInCode(t, `err := validate.MaxItems("siInt64", "query", siInt64Size, 50)`, res)
-
-					assertInCode(t, `siStringIC := swag.SplitByFormat(qvSiString, "csv")`, res)
-					assertInCode(t, `var siStringIR []string`, res)
-					assertInCode(t, `for i, siStringIV := range siStringIC`, res)
-					assertInCode(t, `siStringI := siStringIV`, res)
-					assertInCode(t, `err := validate.MinLength(fmt.Sprintf("%s.%v", "siString", i), "query", siStringI, 5)`, res)
-					assertInCode(t, `err := validate.MaxLength(fmt.Sprintf("%s.%v", "siString", i), "query", siStringI, 50)`, res)
-					assertInCode(t, `err := validate.Pattern(fmt.Sprintf("%s.%v", "siString", i), "query", siStringI, `+"`"+`[A-Z][\w-]+`+"`"+`)`, res)
-					assertInCode(t, `siStringIR = append(siStringIR, siStringI)`, res)
-					assertInCode(t, `o.SiString = siStringIR`, res)
-					assertInCode(t, `siStringSize := int64(len(o.SiString))`, res)
-					assertInCode(t, `err := validate.MinItems("siString", "query", siStringSize, 5)`, res)
-					assertInCode(t, `err := validate.MaxItems("siString", "query", siStringSize, 50)`, res)
-
-					assertInCode(t, `siNestedIC := rawData`, res)
-					assertInCode(t, `var siNestedIR [][][]string`, res)
-					assertInCode(t, `for i, siNestedIV := range siNestedIC`, res)
-					assertInCode(t, `siNestedIIC := swag.SplitByFormat(siNestedIV, "pipes")`, res)
-					assertInCode(t, `var siNestedIIR [][]string`, res)
-					assertInCode(t, `for ii, siNestedIIV := range siNestedIIC {`, res)
-					assertInCode(t, `siNestedIIIC := swag.SplitByFormat(siNestedIIV, "csv")`, res)
-					assertInCode(t, `var siNestedIIIR []string`, res)
-					assertInCode(t, `for iii, siNestedIIIV := range siNestedIIIC`, res)
-					assertInCode(t, `siNestedIII := siNestedIIIV`, res)
-					assertInCode(t, `err := validate.MinLength(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), iii), "query", siNestedIII, 5)`, res)
-					assertInCode(t, `err := validate.MaxLength(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), iii), "query", siNestedIII, 50)`, res)
-					assertInCode(t, `err := validate.Pattern(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), iii), "query", siNestedIII, `+"`"+`[A-Z][\w-]+`+"`"+`)`, res)
-					assertInCode(t, `siNestedIIIR = append(siNestedIIIR, siNestedIII)`, res)
-					assertInCode(t, `siNestedIIiSize := int64(len(siNestedIIIC))`, res) // NOTE(fredbi): fixed variable (nested arrays)
-					assertInCode(t, `err := validate.MinItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), "query", siNestedIIiSize, 3)`, res)
-					assertInCode(t, `err := validate.MaxItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), "query", siNestedIIiSize, 30)`, res)
-					assertInCode(t, `siNestedIIR = append(siNestedIIR, siNestedIIIR)`, res) // NOTE(fredbi): fixed variable (nested arrays)
-					assertInCode(t, `siNestedISize := int64(len(siNestedIIC))`, res)        //NOTE(fredbi): fixed variable (nested arrays)
-					assertInCode(t, `err := validate.MinItems(fmt.Sprintf("%s.%v", "siNested", i), "query", siNestedISize, 2)`, res)
-					assertInCode(t, `err := validate.MaxItems(fmt.Sprintf("%s.%v", "siNested", i), "query", siNestedISize, 20)`, res)
-					assertInCode(t, `siNestedIR = append(siNestedIR, siNestedIIR)`, res) // NOTE(fredbi): fixed variable (nested arrays)
-					assertInCode(t, `o.SiNested = siNestedIR`, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("array_query_params.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	res := string(ff)
+	assertInCode(t, `siBoolIC := swag.SplitByFormat(qvSiBool, "ssv")`, res)
+	assertInCode(t, `var siBoolIR []bool`, res)
+	assertInCode(t, `for i, siBoolIV := range siBoolIC`, res)
+	assertInCode(t, `siBoolI, err := swag.ConvertBool(siBoolIV)`, res)
+	assertInCode(t, `siBoolIR = append(siBoolIR, siBoolI)`, res)
+	assertInCode(t, `o.SiBool = siBoolIR`, res)
+	assertInCode(t, `siBoolSize := int64(len(o.SiBool))`, res)
+	assertInCode(t, `err := validate.MinItems("siBool", "query", siBoolSize, 5)`, res)
+	assertInCode(t, `err := validate.MaxItems("siBool", "query", siBoolSize, 50)`, res)
+
+	assertInCode(t, `siFloatIC := rawData`, res)
+	assertInCode(t, `var siFloatIR []float64`, res)
+	assertInCode(t, `for i, siFloatIV := range siFloatIC`, res)
+	assertInCode(t, `siFloatI, err := swag.ConvertFloat64(siFloatIV)`, res)
+	assertInCode(t, `return errors.InvalidType(fmt.Sprintf("%s.%v", "siFloat", i), "query", "float64", siFloatI)`, res)
+	assertInCode(t, `err := validate.Minimum(fmt.Sprintf("%s.%v", "siFloat", i), "query", float64(siFloatI), 3, true)`, res)
+	assertInCode(t, `err := validate.Maximum(fmt.Sprintf("%s.%v", "siFloat", i), "query", float64(siFloatI), 100, true); err != nil`, res)
+	assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siFloat", i), "query", float64(siFloatI), 1.5)`, res)
+	assertInCode(t, `siFloatIR = append(siFloatIR, siFloatI)`, res)
+	assertInCode(t, `o.SiFloat = siFloatIR`, res)
+	assertInCode(t, `siFloatSize := int64(len(o.SiFloat))`, res)
+	assertInCode(t, `err := validate.MinItems("siFloat", "query", siFloatSize, 5)`, res)
+	assertInCode(t, `err := validate.MaxItems("siFloat", "query", siFloatSize, 50)`, res)
+
+	assertInCode(t, `siFloat32IC := swag.SplitByFormat(qvSiFloat32, "")`, res)
+	assertInCode(t, `var siFloat32IR []float32`, res)
+	assertInCode(t, `for i, siFloat32IV := range siFloat32IC`, res)
+	assertInCode(t, `siFloat32I, err := swag.ConvertFloat32(siFloat32IV)`, res)
+	assertInCode(t, `err := validate.Minimum(fmt.Sprintf("%s.%v", "siFloat32", i), "query", float64(siFloat32I), 3, true)`, res)
+	assertInCode(t, `err := validate.Maximum(fmt.Sprintf("%s.%v", "siFloat32", i), "query", float64(siFloat32I), 100, true)`, res)
+	assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siFloat32", i), "query", float64(siFloat32I), 1.5)`, res)
+	assertInCode(t, `siFloat32IR = append(siFloat32IR, siFloat32I)`, res)
+	assertInCode(t, `o.SiFloat32 = siFloat32IR`, res)
+
+	assertInCode(t, `siFloat64IC := swag.SplitByFormat(qvSiFloat64, "pipes")`, res)
+	assertInCode(t, `var siFloat64IR []float64`, res)
+	assertInCode(t, `for i, siFloat64IV := range siFloat64IC`, res)
+	assertInCode(t, `siFloat64I, err := swag.ConvertFloat64(siFloat64IV)`, res)
+	assertInCode(t, `err := validate.Minimum(fmt.Sprintf("%s.%v", "siFloat64", i), "query", float64(siFloat64I), 3, true)`, res)
+	assertInCode(t, `err := validate.Maximum(fmt.Sprintf("%s.%v", "siFloat64", i), "query", float64(siFloat64I), 100, true)`, res)
+	assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siFloat64", i), "query", float64(siFloat64I), 1.5)`, res)
+	assertInCode(t, `siFloat64IR = append(siFloat64IR, siFloat64I)`, res)
+	assertInCode(t, `o.SiFloat64 = siFloat64IR`, res)
+	assertInCode(t, `siFloat64Size := int64(len(o.SiFloat64))`, res)
+	assertInCode(t, `err := validate.MinItems("siFloat64", "query", siFloat64Size, 5)`, res)
+	assertInCode(t, `err := validate.MaxItems("siFloat64", "query", siFloat64Size, 50)`, res)
+
+	assertInCode(t, `siIntIC := swag.SplitByFormat(qvSiInt, "pipes")`, res)
+	assertInCode(t, `var siIntIR []int64`, res)
+	assertInCode(t, `for i, siIntIV := range siIntIC`, res)
+	assertInCode(t, `siIntI, err := swag.ConvertInt64(siIntIV)`, res)
+	assertInCode(t, `err := validate.MinimumInt(fmt.Sprintf("%s.%v", "siInt", i), "query", int64(siIntI), 8, true)`, res)
+	assertInCode(t, `err := validate.MaximumInt(fmt.Sprintf("%s.%v", "siInt", i), "query", int64(siIntI), 100, true)`, res)
+	assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siInt", i), "query", float64(siIntI), 2)`, res)
+	assertInCode(t, `siIntIR = append(siIntIR, siIntI)`, res)
+	assertInCode(t, `o.SiInt = siIntIR`, res)
+	assertInCode(t, `siIntSize := int64(len(o.SiInt))`, res)
+	assertInCode(t, `err := validate.MinItems("siInt", "query", siIntSize, 5)`, res)
+	assertInCode(t, `err := validate.MaxItems("siInt", "query", siIntSize, 50)`, res)
+
+	assertInCode(t, `siInt32IC := swag.SplitByFormat(qvSiInt32, "tsv")`, res)
+	assertInCode(t, `var siInt32IR []int32`, res)
+	assertInCode(t, `for i, siInt32IV := range siInt32IC`, res)
+	assertInCode(t, `siInt32I, err := swag.ConvertInt32(siInt32IV)`, res)
+	assertInCode(t, `err := validate.MinimumInt(fmt.Sprintf("%s.%v", "siInt32", i), "query", int64(siInt32I), 8, true)`, res)
+	assertInCode(t, `err := validate.MaximumInt(fmt.Sprintf("%s.%v", "siInt32", i), "query", int64(siInt32I), 100, true)`, res)
+	assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siInt32", i), "query", float64(siInt32I), 2)`, res)
+	assertInCode(t, `siInt32IR = append(siInt32IR, siInt32I)`, res)
+	assertInCode(t, `o.SiInt32 = siInt32IR`, res)
+	assertInCode(t, `siFloat32Size := int64(len(o.SiFloat32))`, res)
+	assertInCode(t, `err := validate.MinItems("siFloat32", "query", siFloat32Size, 5)`, res)
+	assertInCode(t, `err := validate.MaxItems("siFloat32", "query", siFloat32Size, 50)`, res)
+	assertInCode(t, `siInt32Size := int64(len(o.SiInt32))`, res)
+	assertInCode(t, `err := validate.MinItems("siInt32", "query", siInt32Size, 5)`, res)
+	assertInCode(t, `err := validate.MaxItems("siInt32", "query", siInt32Size, 50)`, res)
+
+	assertInCode(t, `siInt64IC := swag.SplitByFormat(qvSiInt64, "ssv")`, res)
+	assertInCode(t, `var siInt64IR []int64`, res)
+	assertInCode(t, `for i, siInt64IV := range siInt64IC`, res)
+	assertInCode(t, `siInt64I, err := swag.ConvertInt64(siInt64IV)`, res)
+	assertInCode(t, `err := validate.MinimumInt(fmt.Sprintf("%s.%v", "siInt64", i), "query", int64(siInt64I), 8, true)`, res)
+	assertInCode(t, `err := validate.MaximumInt(fmt.Sprintf("%s.%v", "siInt64", i), "query", int64(siInt64I), 100, true)`, res)
+	assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siInt64", i), "query", float64(siInt64I), 2)`, res)
+	assertInCode(t, `siInt64IR = append(siInt64IR, siInt64I)`, res)
+	assertInCode(t, `o.SiInt64 = siInt64IR`, res)
+	assertInCode(t, `siInt64Size := int64(len(o.SiInt64))`, res)
+	assertInCode(t, `err := validate.MinItems("siInt64", "query", siInt64Size, 5)`, res)
+	assertInCode(t, `err := validate.MaxItems("siInt64", "query", siInt64Size, 50)`, res)
+
+	assertInCode(t, `siStringIC := swag.SplitByFormat(qvSiString, "csv")`, res)
+	assertInCode(t, `var siStringIR []string`, res)
+	assertInCode(t, `for i, siStringIV := range siStringIC`, res)
+	assertInCode(t, `siStringI := siStringIV`, res)
+	assertInCode(t, `err := validate.MinLength(fmt.Sprintf("%s.%v", "siString", i), "query", siStringI, 5)`, res)
+	assertInCode(t, `err := validate.MaxLength(fmt.Sprintf("%s.%v", "siString", i), "query", siStringI, 50)`, res)
+	assertInCode(t, `err := validate.Pattern(fmt.Sprintf("%s.%v", "siString", i), "query", siStringI, `+"`"+`[A-Z][\w-]+`+"`"+`)`, res)
+	assertInCode(t, `siStringIR = append(siStringIR, siStringI)`, res)
+	assertInCode(t, `o.SiString = siStringIR`, res)
+	assertInCode(t, `siStringSize := int64(len(o.SiString))`, res)
+	assertInCode(t, `err := validate.MinItems("siString", "query", siStringSize, 5)`, res)
+	assertInCode(t, `err := validate.MaxItems("siString", "query", siStringSize, 50)`, res)
+
+	assertInCode(t, `siNestedIC := rawData`, res)
+	assertInCode(t, `var siNestedIR [][][]string`, res)
+	assertInCode(t, `for i, siNestedIV := range siNestedIC`, res)
+	assertInCode(t, `siNestedIIC := swag.SplitByFormat(siNestedIV, "pipes")`, res)
+	assertInCode(t, `var siNestedIIR [][]string`, res)
+	assertInCode(t, `for ii, siNestedIIV := range siNestedIIC {`, res)
+	assertInCode(t, `siNestedIIIC := swag.SplitByFormat(siNestedIIV, "csv")`, res)
+	assertInCode(t, `var siNestedIIIR []string`, res)
+	assertInCode(t, `for iii, siNestedIIIV := range siNestedIIIC`, res)
+	assertInCode(t, `siNestedIII := siNestedIIIV`, res)
+	assertInCode(t, `err := validate.MinLength(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), iii), "query", siNestedIII, 5)`, res)
+	assertInCode(t, `err := validate.MaxLength(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), iii), "query", siNestedIII, 50)`, res)
+	assertInCode(t, `err := validate.Pattern(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), iii), "query", siNestedIII, `+"`"+`[A-Z][\w-]+`+"`"+`)`, res)
+	assertInCode(t, `siNestedIIIR = append(siNestedIIIR, siNestedIII)`, res)
+	assertInCode(t, `siNestedIIiSize := int64(len(siNestedIIIC))`, res) // NOTE(fredbi): fixed variable (nested arrays)
+	assertInCode(t, `err := validate.MinItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), "query", siNestedIIiSize, 3)`, res)
+	assertInCode(t, `err := validate.MaxItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), "query", siNestedIIiSize, 30)`, res)
+	assertInCode(t, `siNestedIIR = append(siNestedIIR, siNestedIIIR)`, res) // NOTE(fredbi): fixed variable (nested arrays)
+	assertInCode(t, `siNestedISize := int64(len(siNestedIIC))`, res)        // NOTE(fredbi): fixed variable (nested arrays)
+	assertInCode(t, `err := validate.MinItems(fmt.Sprintf("%s.%v", "siNested", i), "query", siNestedISize, 2)`, res)
+	assertInCode(t, `err := validate.MaxItems(fmt.Sprintf("%s.%v", "siNested", i), "query", siNestedISize, 20)`, res)
+	assertInCode(t, `siNestedIR = append(siNestedIR, siNestedIIR)`, res) // NOTE(fredbi): fixed variable (nested arrays)
+	assertInCode(t, `o.SiNested = siNestedIR`, res)
 }
 
 func assertParams(t *testing.T, fixtureConfig map[string]map[string][]string, fixture string, minimalFlatten bool, withExpand bool) {
 	fixtureSpec := path.Base(fixture)
-	tassert := assert.New(t)
-	for fixtureIndex, fixtureContents := range fixtureConfig {
-		var gen codeGenOpBuilder
-		var err error
-		switch {
-		case minimalFlatten && !withExpand:
-			// proceed with minimal spec flattening
-			gen, err = opBuilder(fixtureIndex, fixture)
-		case !minimalFlatten:
-			// proceed with full flattening
-			gen, err = opBuilderWithFlatten(fixtureIndex, fixture)
-		default:
-			// proceed with spec expansion
-			gen, err = opBuilderWithExpand(fixtureIndex, fixture)
-		}
-		if tassert.NoError(err) {
+
+	for k, toPin := range fixtureConfig {
+		fixtureIndex := k
+		fixtureContents := toPin
+		t.Run(fmt.Sprintf("%s-%s", t.Name(), fixtureIndex), func(t *testing.T) {
+			t.Parallel()
+
+			var gen codeGenOpBuilder
+			var err error
+			switch {
+			case minimalFlatten && !withExpand:
+				// proceed with minimal spec flattening
+				gen, err = opBuilder(fixtureIndex, fixture)
+			case !minimalFlatten:
+				// proceed with full flattening
+				gen, err = opBuilderWithFlatten(fixtureIndex, fixture)
+			default:
+				// proceed with spec expansion
+				gen, err = opBuilderWithExpand(fixtureIndex, fixture)
+			}
+			require.NoError(t, err)
+
 			op, err := gen.MakeOperation()
-			if tassert.NoError(err) {
-				opts := opts()
-				for fixtureTemplate, expectedCode := range fixtureContents {
-					buf := bytes.NewBuffer(nil)
-					err := templates.MustGet(fixtureTemplate).Execute(buf, op)
-					if tassert.NoError(err, "Expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate) {
-						ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes())
-						if tassert.NoError(err, "Expected formatting to go well on %s with template %s", fixtureSpec, fixtureTemplate) {
-							res := string(ff)
-							for line, codeLine := range expectedCode {
-								if !assertInCode(t, strings.TrimSpace(codeLine), res) {
-									t.Logf("Code expected did not match for fixture %s at line %d", fixtureSpec, line)
-								}
-							}
-						} else {
-							fmt.Println(buf.String())
-						}
+			require.NoError(t, err)
+
+			opts := opts()
+			for fixtureTemplate, expectedCode := range fixtureContents {
+				buf := bytes.NewBuffer(nil)
+				require.NoErrorf(t, opts.templates.MustGet(fixtureTemplate).Execute(buf, op),
+					"expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate)
+
+				ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes())
+				require.NoErrorf(t, err, "unexpect format error on %s with template %s\n%s",
+					fixtureSpec, fixtureTemplate, buf.String())
+
+				res := string(ff)
+				for line, codeLine := range expectedCode {
+					if !assertInCode(t, strings.TrimSpace(codeLine), res) {
+						t.Logf("code expected did not match for fixture %s at line %d", fixtureSpec, line)
 					}
 				}
 			}
-		}
+		})
 	}
 }
 
 func TestGenParameter_Issue909(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
 
-	assert := assert.New(t)
 	fixtureConfig := map[string]map[string][]string{
 		"1": { // fixture index
 			"serverParameter": { // executed template
@@ -1521,43 +1404,45 @@ func TestGenParameter_Issue909(t *testing.T) {
 		},
 	}
 
-	for fixtureIndex, fixtureContents := range fixtureConfig {
-		fixtureSpec := strings.Join([]string{"fixture-909-", fixtureIndex, ".yaml"}, "")
-		gen, err := opBuilder("getOptional", filepath.Join("..", "fixtures", "bugs", "909", fixtureSpec))
-		if assert.NoError(err) {
+	for k, toPin := range fixtureConfig {
+		fixtureIndex := k
+		fixtureContents := toPin
+
+		t.Run(fmt.Sprintf("%s-%s", t.Name(), fixtureIndex), func(t *testing.T) {
+			t.Parallel()
+
+			fixtureSpec := strings.Join([]string{"fixture-909-", fixtureIndex, ".yaml"}, "")
+			gen, err := opBuilder("getOptional", filepath.Join("..", "fixtures", "bugs", "909", fixtureSpec))
+			require.NoError(t, err)
+
 			op, err := gen.MakeOperation()
-			if assert.NoError(err) {
-				opts := opts()
-				for fixtureTemplate, expectedCode := range fixtureContents {
-					buf := bytes.NewBuffer(nil)
-					err := templates.MustGet(fixtureTemplate).Execute(buf, op)
-					if assert.NoError(err, "Expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate) {
-						ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes())
-						if assert.NoError(err, "Expected formatting to go well on %s with template %s", fixtureSpec, fixtureTemplate) {
-							res := string(ff)
-							for line, codeLine := range expectedCode {
-								if !assertInCode(t, strings.TrimSpace(codeLine), res) {
-									t.Logf("Code expected did not match for fixture %s at line %d", fixtureSpec, line)
-								}
-							}
-						} else {
-							fmt.Println(buf.String())
-						}
+			require.NoError(t, err)
+
+			opts := opts()
+			for fixtureTemplate, expectedCode := range fixtureContents {
+				buf := bytes.NewBuffer(nil)
+				err := opts.templates.MustGet(fixtureTemplate).Execute(buf, op)
+				require.NoErrorf(t, err, "expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate)
+
+				ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes())
+				require.NoError(t, err, "expected formatting to go well on %s with template %s\n%s",
+					fixtureSpec, fixtureTemplate, buf.String())
+
+				res := string(ff)
+				for line, codeLine := range expectedCode {
+					if !assertInCode(t, strings.TrimSpace(codeLine), res) {
+						t.Logf("Code expected did not match for fixture %s at line %d", fixtureSpec, line)
 					}
 				}
 			}
-		}
+		})
 	}
 }
 
 // verifies that validation method is called on body param with $ref
 func TestGenParameter_Issue1237(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
 
-	assert := assert.New(t)
 	fixtureConfig := map[string]map[string][]string{
 		"1": { // fixture index
 			"serverParameter": { // executed template
@@ -1575,26 +1460,24 @@ func TestGenParameter_Issue1237(t *testing.T) {
 	for _, fixtureContents := range fixtureConfig {
 		fixtureSpec := strings.Join([]string{"fixture-1237", ".json"}, "")
 		gen, err := opBuilder("add sg", filepath.Join("..", "fixtures", "bugs", "1237", fixtureSpec))
-		if assert.NoError(err) {
-			op, err := gen.MakeOperation()
-			if assert.NoError(err) {
-				opts := opts()
-				for fixtureTemplate, expectedCode := range fixtureContents {
-					buf := bytes.NewBuffer(nil)
-					err := templates.MustGet(fixtureTemplate).Execute(buf, op)
-					if assert.NoError(err, "Expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate) {
-						ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes())
-						if assert.NoError(err, "Expected formatting to go well on %s with template %s", fixtureSpec, fixtureTemplate) {
-							res := string(ff)
-							for line, codeLine := range expectedCode {
-								if !assertInCode(t, strings.TrimSpace(codeLine), res) {
-									t.Logf("Code expected did not match for fixture %s at line %d", fixtureSpec, line)
-								}
-							}
-						} else {
-							fmt.Println(buf.String())
-						}
-					}
+		require.NoError(t, err)
+
+		op, err := gen.MakeOperation()
+		require.NoError(t, err)
+
+		opts := opts()
+		for fixtureTemplate, expectedCode := range fixtureContents {
+			buf := bytes.NewBuffer(nil)
+			require.NoErrorf(t, opts.templates.MustGet(fixtureTemplate).Execute(buf, op),
+				"expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate)
+
+			ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes())
+			require.NoErrorf(t, err, "expected formatting to go well on %s with template %s: %s", fixtureSpec, fixtureTemplate, buf.String())
+
+			res := string(ff)
+			for line, codeLine := range expectedCode {
+				if !assertInCode(t, strings.TrimSpace(codeLine), res) {
+					t.Logf("Code expected did not match for fixture %s at line %d", fixtureSpec, line)
 				}
 			}
 		}
@@ -1602,12 +1485,8 @@ func TestGenParameter_Issue1237(t *testing.T) {
 }
 
 func TestGenParameter_Issue1392(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
 
-	assert := assert.New(t)
 	fixtureConfig := map[string]map[string][]string{
 		"1": { // fixture index
 			"serverParameter": { // executed template
@@ -1756,81 +1635,77 @@ func TestGenParameter_Issue1392(t *testing.T) {
 		},
 	}
 
-	for fixtureIndex, fixtureContents := range fixtureConfig {
-		fixtureSpec := strings.Join([]string{"fixture-1392-", fixtureIndex, ".yaml"}, "")
-		// pick selected operation id in fixture
-		operationToTest := ""
-		switch fixtureIndex {
-		case "1":
-			operationToTest = "PatchSomeResource"
-		case "2":
-			operationToTest = "PostBodybuilder20"
-		case "3":
-			operationToTest = "PostBodybuilder26"
-		case "4":
-			operationToTest = "PostBodybuilder27"
-		case "5":
-			operationToTest = "Bodybuilder23"
-		}
-		gen, err := opBuilder(operationToTest, filepath.Join("..", "fixtures", "bugs", "1392", fixtureSpec))
-		if assert.NoError(err) {
+	for k, toPin := range fixtureConfig {
+		fixtureIndex := k
+		fixtureContents := toPin
+		t.Run(fmt.Sprintf("%s-%s", t.Name(), k), func(t *testing.T) {
+			fixtureSpec := strings.Join([]string{"fixture-1392-", fixtureIndex, ".yaml"}, "")
+			// pick selected operation id in fixture
+			operationToTest := ""
+			switch fixtureIndex {
+			case "1":
+				operationToTest = "PatchSomeResource"
+			case "2":
+				operationToTest = "PostBodybuilder20"
+			case "3":
+				operationToTest = "PostBodybuilder26"
+			case "4":
+				operationToTest = "PostBodybuilder27"
+			case "5":
+				operationToTest = "Bodybuilder23"
+			}
+
+			gen, err := opBuilder(operationToTest, filepath.Join("..", "fixtures", "bugs", "1392", fixtureSpec))
+			require.NoError(t, err)
+
 			op, err := gen.MakeOperation()
-			if assert.NoError(err) {
-				opts := opts()
-				for fixtureTemplate, expectedCode := range fixtureContents {
-					buf := bytes.NewBuffer(nil)
-					err := templates.MustGet(fixtureTemplate).Execute(buf, op)
-					if assert.NoError(err, "Expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate) {
-						ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes())
-						if assert.NoError(err, "Expected formatting to go well on %s with template %s", fixtureSpec, fixtureTemplate) {
-							res := string(ff)
-							for line, codeLine := range expectedCode {
-								if !assertInCode(t, strings.TrimSpace(codeLine), res) {
-									t.Logf("Code expected did not match for fixture %s at line %d", fixtureSpec, line)
-								}
-							}
-						} else {
-							fmt.Println(buf.String())
-						}
+			require.NoError(t, err)
+
+			opts := opts()
+			for fixtureTemplate, expectedCode := range fixtureContents {
+				buf := bytes.NewBuffer(nil)
+				require.NoError(t, templates.MustGet(fixtureTemplate).Execute(buf, op),
+					"expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate)
+
+				ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes())
+				require.NoError(t, err, "expected formatting to go well on %s with template %s\n%s", fixtureSpec, fixtureTemplate, buf.String())
+
+				res := string(ff)
+				for line, codeLine := range expectedCode {
+					if !assertInCode(t, strings.TrimSpace(codeLine), res) {
+						t.Logf("Code expected did not match for fixture %s at line %d", fixtureSpec, line)
 					}
 				}
 			}
-		}
+		})
 	}
 }
 
 func TestGenParameter_Issue1513(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
-	assert := assert.New(t)
 	var assertion = `r.SetBodyParam(o.Something)`
+
 	gen, err := opBuilderWithFlatten("put-enum", "../fixtures/bugs/1513/enums.yaml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("move_clusters_parameters.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, assertion, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("move_clusters_parameters.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %v\n%s", err, buf.String())
+
+	res := string(ff)
+	assertInCode(t, assertion, res)
 }
 
 // Body param validation on empty objects
 func TestGenParameter_Issue1536(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
 
 	// testing fixture-1536.yaml with flatten
 	// param body with array of empty objects
@@ -2148,10 +2023,7 @@ func TestGenParameter_Issue1536(t *testing.T) {
 }
 
 func TestGenParameter_Issue15362(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
 
 	fixtureConfig := map[string]map[string][]string{
 		// load expectations for parameters in operation get_nested_with_validations_parameters.go
@@ -2380,10 +2252,8 @@ func TestGenParameter_Issue15362(t *testing.T) {
 }
 
 func TestGenParameter_Issue1536_Maps(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	t.Parallel()
+	defer discardOutput()()
 
 	fixtureConfig := map[string]map[string][]string{
 
@@ -3016,10 +2886,8 @@ func TestGenParameter_Issue1536_Maps(t *testing.T) {
 }
 
 func TestGenParameter_Issue1536_MapsWithExpand(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	t.Parallel()
+	defer discardOutput()()
 
 	fixtureConfig := map[string]map[string][]string{
 		// load expectations for parameters in operation get_map_of_array_of_map_parameters.go
@@ -3262,10 +3130,8 @@ func TestGenParameter_Issue1536_MapsWithExpand(t *testing.T) {
 	assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1536", "fixture-1536-3.yaml"), true, true)
 }
 func TestGenParameter_Issue1536_MoreMaps(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	t.Parallel()
+	defer discardOutput()()
 
 	// testing fixture-1536-4.yaml with flatten
 	// param body with maps
@@ -4003,10 +3869,8 @@ func TestGenParameter_Issue1536_MoreMaps(t *testing.T) {
 }
 
 func TestGenParameter_Issue15362_WithExpand(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	t.Parallel()
+	defer discardOutput()()
 
 	fixtureConfig := map[string]map[string][]string{
 		// load expectations for parameters in operation get_nested_required_parameters.go
@@ -4072,6 +3936,9 @@ func TestGenParameter_Issue15362_WithExpand(t *testing.T) {
 }
 
 func TestGenParameter_Issue1548_base64(t *testing.T) {
+	t.Parallel()
+	defer discardOutput()()
+
 	// testing fixture-1548.yaml with flatten
 	// My App API
 	fixtureConfig := map[string]map[string][]string{
@@ -4144,10 +4011,9 @@ func TestGenParameter_Issue1548_base64(t *testing.T) {
 }
 
 func TestGenParameter_1572(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	t.Parallel()
+	defer discardOutput()()
+
 	// testing fixture-1572.yaml with minimal flatten
 	// edge cases for operations schemas
 
@@ -4278,10 +4144,9 @@ func TestGenParameter_1572(t *testing.T) {
 }
 
 func TestGenParameter_1637(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	t.Parallel()
+	defer discardOutput()()
+
 	// testing fixture-1637.yaml with minimal flatten
 	// slice of polymorphic type in body param
 
@@ -4298,10 +4163,9 @@ func TestGenParameter_1637(t *testing.T) {
 }
 
 func TestGenParameter_1755(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	t.Parallel()
+	defer discardOutput()()
+
 	// testing fixture-1755.yaml with minimal flatten
 	// body param is array with slice validation (e.g. minItems): initialize array with body
 
@@ -4319,10 +4183,9 @@ func TestGenParameter_1755(t *testing.T) {
 }
 
 func TestGenClientParameter_1490(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	t.Parallel()
+	defer discardOutput()()
+
 	// testing fixture-1490.yaml with minimal flatten
 	// body param is interface
 
@@ -4349,10 +4212,9 @@ func TestGenClientParameter_1490(t *testing.T) {
 }
 
 func TestGenClientParameter_973(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	t.Parallel()
+	defer discardOutput()()
+
 	// testing fixture-973.yaml with minimal flatten
 	// header param is UUID, with or without required constraint
 
@@ -4370,10 +4232,9 @@ func TestGenClientParameter_973(t *testing.T) {
 }
 
 func TestGenClientParameter_1020(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	t.Parallel()
+	defer discardOutput()()
+
 	// testing fixture-1020.yaml with minimal flatten
 	// param is File
 
@@ -4390,10 +4251,9 @@ func TestGenClientParameter_1020(t *testing.T) {
 }
 
 func TestGenClientParameter_1339(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	t.Parallel()
+	defer discardOutput()()
+
 	// testing fixture-1339.yaml with minimal flatten
 	// param is binary
 
@@ -4410,11 +4270,11 @@ func TestGenClientParameter_1339(t *testing.T) {
 }
 
 func TestGenClientParameter_1937(t *testing.T) {
+	t.Parallel()
+	defer discardOutput()()
+
 	// names starting with a number
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+
 	// testing fixture-1339.yaml with minimal flatten
 	// param is binary
 
@@ -4432,53 +4292,45 @@ func TestGenClientParameter_1937(t *testing.T) {
 }
 
 func TestGenParameter_Issue2167(t *testing.T) {
-	assert := assert.New(t)
+	t.Parallel()
+	defer discardOutput()()
 
 	gen, err := opBuilder("xGoNameInParams", "../fixtures/enhancements/2167/swagger.yml")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("clientParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("x_go_name_in_params_parameters.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertRegexpInCode(t, `(?m)^\tMyPathName\s+string$`, res)
-					assertRegexpInCode(t, `(?m)^\tTestRegion\s+string$`, res)
-					assertRegexpInCode(t, `(?m)^\tMyQueryCount\s+\*int64$`, res)
-					assertRegexpInCode(t, `(?m)^\tTestLimit\s+\*int64$`, res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("clientParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("x_go_name_in_params_parameters.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	res := string(ff)
+	assertRegexpInCode(t, `(?m)^\tMyPathName\s+string$`, res)
+	assertRegexpInCode(t, `(?m)^\tTestRegion\s+string$`, res)
+	assertRegexpInCode(t, `(?m)^\tMyQueryCount\s+\*int64$`, res)
+	assertRegexpInCode(t, `(?m)^\tTestLimit\s+\*int64$`, res)
 }
+
 func TestGenParameter_Issue2273(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
-	assert := assert.New(t)
+	t.Parallel()
+	defer discardOutput()()
 
 	gen, err := opBuilder("postSnapshot", "../fixtures/bugs/2273/swagger.json")
-	if assert.NoError(err) {
-		op, err := gen.MakeOperation()
-		if assert.NoError(err) {
-			buf := bytes.NewBuffer(nil)
-			opts := opts()
-			err := templates.MustGet("serverParameter").Execute(buf, op)
-			if assert.NoError(err) {
-				ff, err := opts.LanguageOpts.FormatContent("post_snapshot_parameters.go", buf.Bytes())
-				if assert.NoError(err) {
-					res := string(ff)
-					assertInCode(t, "o.Snapshot = *(value.(*io.ReadCloser))", res)
-				} else {
-					fmt.Println(buf.String())
-				}
-			}
-		}
-	}
+	require.NoError(t, err)
+
+	op, err := gen.MakeOperation()
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	opts := opts()
+	require.NoError(t, opts.templates.MustGet("serverParameter").Execute(buf, op))
+
+	ff, err := opts.LanguageOpts.FormatContent("post_snapshot_parameters.go", buf.Bytes())
+	require.NoErrorf(t, err, "unexpected format error: %s\n%s", err, buf.String())
+
+	assertInCode(t, "o.Snapshot = *(value.(*io.ReadCloser))", string(ff))
 }
diff --git a/generator/schemavalidation_test.go b/generator/schemavalidation_test.go
index 01da60f6..550dea37 100644
--- a/generator/schemavalidation_test.go
+++ b/generator/schemavalidation_test.go
@@ -16,7 +16,6 @@ package generator
 
 import (
 	"bytes"
-	"regexp"
 	"testing"
 
 	"github.com/go-openapi/loads"
@@ -25,64 +24,6 @@ import (
 	"github.com/stretchr/testify/require"
 )
 
-// testing utilities for codegen assertions
-
-func reqm(str string) *regexp.Regexp {
-	return regexp.MustCompile(regexp.QuoteMeta(str))
-}
-
-func reqOri(str string) *regexp.Regexp {
-	return regexp.MustCompile(str)
-}
-
-func assertInCode(t testing.TB, expr, code string) bool {
-	return assert.Regexp(t, reqm(expr), code)
-}
-
-func assertRegexpInCode(t testing.TB, expr, code string) bool {
-	return assert.Regexp(t, reqOri(expr), code)
-}
-
-func assertNotInCode(t testing.TB, expr, code string) bool {
-	return assert.NotRegexp(t, reqm(expr), code)
-}
-
-// Unused
-// func assertRegexpNotInCode(t testing.TB, expr, code string) bool {
-// 	return assert.NotRegexp(t, reqOri(expr), code)
-// }
-
-func requireValidation(t testing.TB, pth, expr string, gm GenSchema) {
-	if !assertValidation(t, pth, expr, gm) {
-		t.FailNow()
-	}
-}
-
-func assertValidation(t testing.TB, pth, expr string, gm GenSchema) bool {
-	if !assert.True(t, gm.HasValidations, "expected the schema to have validations") {
-		return false
-	}
-	if !assert.Equal(t, pth, gm.Path, "paths don't match") {
-		return false
-	}
-	if !assert.Equal(t, expr, gm.ValueExpression, "expressions don't match") {
-		return false
-	}
-	return true
-}
-
-func funcBody(code string, signature string) string {
-	submatches := regexp.MustCompile(
-		"\\nfunc \\([a-zA-Z_][a-zA-Z0-9_]* " + regexp.QuoteMeta(signature) + " {\\n" + // function signature
-			"((([^}\\n][^\\n]*)?\\n)*)}\\n", // function body
-	).FindStringSubmatch(code)
-
-	if submatches == nil {
-		return ""
-	}
-	return submatches[1]
-}
-
 func TestSchemaValidation_RequiredProps(t *testing.T) {
 	specDoc, err := loads.Spec("../fixtures/codegen/todolist.schemavalidation.yml")
 	require.NoError(t, err)
diff --git a/generator/server_test.go b/generator/server_test.go
index a41672c3..ff54f443 100644
--- a/generator/server_test.go
+++ b/generator/server_test.go
@@ -4,7 +4,6 @@ import (
 	"bytes"
 	"errors"
 	"io/ioutil"
-	"log"
 	"os"
 	"path/filepath"
 	"regexp"
@@ -65,8 +64,7 @@ func testAppGenerator(t testing.TB, specPath, name string) (*appGenerator, error
 }
 
 func TestServer_UrlEncoded(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	gen, err := testAppGenerator(t, "../fixtures/codegen/simplesearch.yml", "search")
 	require.NoError(t, err)
@@ -75,7 +73,7 @@ func TestServer_UrlEncoded(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	require.NoError(t, templates.MustGet("serverBuilder").Execute(buf, app))
+	require.NoError(t, app.GenOpts.templates.MustGet("serverBuilder").Execute(buf, app))
 
 	formatted, err := app.GenOpts.LanguageOpts.FormatContent("search_api.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
@@ -84,18 +82,16 @@ func TestServer_UrlEncoded(t *testing.T) {
 	assert.Regexp(t, "UrlformConsumer:\\s+runtime\\.DiscardConsumer", res)
 
 	buf = bytes.NewBuffer(nil)
-	require.NoError(t, templates.MustGet("serverConfigureapi").Execute(buf, app))
+	require.NoError(t, app.GenOpts.templates.MustGet("serverConfigureapi").Execute(buf, app))
 
 	formatted, err = app.GenOpts.LanguageOpts.FormatContent("configure_search_api.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
 
-	res = string(formatted)
-	assertInCode(t, "api.UrlformConsumer = runtime.DiscardConsumer", res)
+	assertInCode(t, "api.UrlformConsumer = runtime.DiscardConsumer", string(formatted))
 }
 
 func TestServer_MultipartForm(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	gen, err := testAppGenerator(t, "../fixtures/codegen/shipyard.yml", "shipyard")
 	require.NoError(t, err)
@@ -104,27 +100,24 @@ func TestServer_MultipartForm(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	require.NoError(t, templates.MustGet("serverBuilder").Execute(buf, app))
+	require.NoError(t, app.GenOpts.templates.MustGet("serverBuilder").Execute(buf, app))
 
 	formatted, err := app.GenOpts.LanguageOpts.FormatContent("shipyard_api.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
 
-	res := string(formatted)
-	assert.Regexp(t, "MultipartformConsumer:\\s+runtime\\.DiscardConsumer", res)
+	assert.Regexp(t, "MultipartformConsumer:\\s+runtime\\.DiscardConsumer", string(formatted))
 
 	buf = bytes.NewBuffer(nil)
-	require.NoError(t, templates.MustGet("serverConfigureapi").Execute(buf, app))
+	require.NoError(t, app.GenOpts.templates.MustGet("serverConfigureapi").Execute(buf, app))
 
 	formatted, err = app.GenOpts.LanguageOpts.FormatContent("configure_shipyard_api.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
 
-	res = string(formatted)
-	assertInCode(t, "api.MultipartformConsumer = runtime.DiscardConsumer", res)
+	assertInCode(t, "api.MultipartformConsumer = runtime.DiscardConsumer", string(formatted))
 }
 
 func TestServer_InvalidSpec(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	opts := testGenOpts()
 	opts.Spec = invalidSpecExample
@@ -134,8 +127,7 @@ func TestServer_InvalidSpec(t *testing.T) {
 }
 
 func TestServer_TrailingSlash(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	gen, err := testAppGenerator(t, "../fixtures/bugs/899/swagger.yml", "trailing slash")
 	require.NoError(t, err)
@@ -144,18 +136,16 @@ func TestServer_TrailingSlash(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	require.NoError(t, templates.MustGet("serverBuilder").Execute(buf, app))
+	require.NoError(t, app.GenOpts.templates.MustGet("serverBuilder").Execute(buf, app))
 
 	formatted, err := app.GenOpts.LanguageOpts.FormatContent("shipyard_api.go", buf.Bytes())
 	require.NoError(t, err, buf.String())
 
-	res := string(formatted)
-	assertInCode(t, `o.handlers["GET"]["/trailingslashpath"]`, res)
+	assertInCode(t, `o.handlers["GET"]["/trailingslashpath"]`, string(formatted))
 }
 
 func TestServer_Issue987(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	gen, err := testAppGenerator(t, "../fixtures/bugs/987/swagger.yml", "deeper consumes produces")
 	require.NoError(t, err)
@@ -164,7 +154,7 @@ func TestServer_Issue987(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	require.NoError(t, templates.MustGet("serverBuilder").Execute(buf, app))
+	require.NoError(t, app.GenOpts.templates.MustGet("serverBuilder").Execute(buf, app))
 
 	formatted, err := app.GenOpts.LanguageOpts.FormatContent("shipyard_api.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
@@ -177,8 +167,7 @@ func TestServer_Issue987(t *testing.T) {
 }
 
 func TestServer_FilterByTag(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	gen, err := testAppGenerator(t, "../fixtures/codegen/simplesearch.yml", "search")
 	require.NoError(t, err)
@@ -188,7 +177,7 @@ func TestServer_FilterByTag(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	require.NoError(t, templates.MustGet("serverBuilder").Execute(buf, app))
+	require.NoError(t, app.GenOpts.templates.MustGet("serverBuilder").Execute(buf, app))
 
 	formatted, err := app.GenOpts.LanguageOpts.FormatContent("search_api.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
@@ -198,67 +187,48 @@ func TestServer_FilterByTag(t *testing.T) {
 	assertNotInCode(t, `o.handlers["POST"]["/tasks"]`, res)
 }
 
-// Checking error handling code: panic on mismatched template
-// High level test with AppGenerator
-func badTemplateCall() {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+func TestServer_BadTemplate(t *testing.T) {
+	// Checking error handling code: panic on mismatched template
+
+	defer discardOutput()()
 
 	gen, err := testAppGenerator(nil, "../fixtures/bugs/899/swagger.yml", "trailing slash")
-	if err != nil {
-		return
-	}
-	app, err := gen.makeCodegenApp()
-	log.SetOutput(ioutil.Discard)
-	if err != nil {
-		return
-	}
-	buf := bytes.NewBuffer(nil)
-	r := templates.MustGet("serverBuilderX").Execute(buf, app)
+	require.NoError(t, err)
 
-	// Should never reach here
-	log.Printf("%+v\n", r)
-}
+	app, err := gen.makeCodegenApp()
+	require.NoError(t, err)
 
-func TestServer_BadTemplate(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	badTemplateCall := func() {
+		buf := bytes.NewBuffer(nil)
+		_ = app.GenOpts.templates.MustGet("serverBuilderX").Execute(buf, app)
+	}
 
 	assert.Panics(t, badTemplateCall, "templates.MustGet() did not panic() as currently expected")
 }
 
-// Checking error handling code: panic on bad parsing template
-// High level test with AppGenerator
-func badParseCall() {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+func TestServer_ErrorParsingTemplate(t *testing.T) {
+	// Checking error handling code: panic on bad parsing template
+	// High level test with AppGenerator
 
-	var badParse = `{{{ define "T1" }}T1{{end}}{{ define "T2" }}T2{{end}}`
+	defer discardOutput()()
 
-	_ = templates.AddFile("badparse", badParse)
-	gen, _ := testAppGenerator(nil, "../fixtures/bugs/899/swagger.yml", "trailing slash")
-	app, _ := gen.makeCodegenApp()
-	log.SetOutput(ioutil.Discard)
-	tpl := templates.MustGet("badparse")
+	var badParse = `{{{ define "T1" }}T1{{end}}{{ define "T2" }}T2{{end}}`
 
-	// Should never reach here
-	buf := bytes.NewBuffer(nil)
-	r := tpl.Execute(buf, app)
+	gen, err := testAppGenerator(nil, "../fixtures/bugs/899/swagger.yml", "trailing slash")
+	require.NoError(t, err)
 
-	log.Printf("%+v\n", r)
-}
+	require.Error(t, gen.GenOpts.templates.AddFile("badparse", badParse)) // template is not loaded
 
-func TestServer_ErrorParsingTemplate(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	badParseCall := func() {
+		_ = templates.MustGet("badparse") // MustGet panics
+	}
 
 	assert.Panics(t, badParseCall, "templates.MustGet() did not panic() as currently expected")
 }
 
 func TestServer_OperationGroups(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
+	defer discardOutput()()
 	defer func() {
-		log.SetOutput(os.Stdout)
 		_ = os.RemoveAll(filepath.Join(".", "restapi"))
 		_ = os.RemoveAll(filepath.Join(".", "search"))
 		_ = os.RemoveAll(filepath.Join(".", "tasks"))
@@ -278,8 +248,9 @@ func TestServer_OperationGroups(t *testing.T) {
 			FileName: "{{ (snakize (pascalize .Name)) }}_opgroup_test.gol",
 		},
 	}
+
 	err = gen.Generate()
-	require.Error(t, err)                                                      // This attempts fails: template not declared
+	require.Error(t, err)
 	assert.Contains(t, strings.ToLower(err.Error()), "template doesn't exist") // Tolerates case variations on error message
 
 	var opGroupTpl = `
@@ -288,17 +259,19 @@ func TestServer_OperationGroups(t *testing.T) {
 {{ range .Operations }}
 	// OperationName={{.Name}}
 {{end}}`
-	_ = templates.AddFile("opGroupTest", opGroupTpl)
-	err = gen.Generate()
-	require.NoError(t, err)
-	genContent, erf := ioutil.ReadFile("./search/search_opgroup_test.gol")
-	assert.NoError(t, erf, "Generator should have written a file")
+	_ = gen.GenOpts.templates.AddFile("opGroupTest", opGroupTpl)
+	require.NoError(t, gen.Generate())
+
+	genContent, err := ioutil.ReadFile("./search/search_opgroup_test.gol")
+	require.NoError(t, err, "Generator should have written a file")
+
 	assert.Contains(t, string(genContent), "// OperationGroupName=search")
 	assert.Contains(t, string(genContent), "// RootPackage=operations")
 	assert.Contains(t, string(genContent), "// OperationName=search")
 
-	genContent, erf = ioutil.ReadFile("./tasks/tasks_opgroup_test.gol")
-	require.NoError(t, erf, "Generator should have written a file")
+	genContent, err = ioutil.ReadFile("./tasks/tasks_opgroup_test.gol")
+	require.NoError(t, err, "Generator should have written a file")
+
 	assert.Contains(t, string(genContent), "// OperationGroupName=tasks")
 	assert.Contains(t, string(genContent), "// RootPackage=operations")
 	assert.Contains(t, string(genContent), "// OperationName=createTask")
@@ -308,8 +281,7 @@ func TestServer_OperationGroups(t *testing.T) {
 }
 
 func TestServer_Issue1301(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	gen, err := testAppGenerator(t, "../fixtures/enhancements/1301/swagger.yml", "custom producers")
 	require.NoError(t, err)
@@ -318,9 +290,11 @@ func TestServer_Issue1301(t *testing.T) {
 	require.NoError(t, err)
 
 	buf := bytes.NewBuffer(nil)
-	require.NoError(t, templates.MustGet("serverBuilder").Execute(buf, app))
+	require.NoError(t, app.GenOpts.templates.MustGet("serverBuilder").Execute(buf, app))
+
 	formatted, err := app.GenOpts.LanguageOpts.FormatContent("shipyard_api.go", buf.Bytes())
 	require.NoErrorf(t, err, buf.String())
+
 	res := string(formatted)
 
 	// initialisation in New<Name>API function
@@ -337,8 +311,7 @@ func TestServer_Issue1301(t *testing.T) {
 }
 
 func TestServer_PreServerShutdown_Issue2108(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	gen, err := testAppGenerator(t, "../fixtures/enhancements/2108/swagger.yml", "pre server shutdown")
 	require.NoError(t, err)
@@ -369,8 +342,7 @@ func TestServer_PreServerShutdown_Issue2108(t *testing.T) {
 }
 
 func TestServer_Issue1557(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	gen, err := testAppGenerator(t, "../fixtures/enhancements/1557/swagger.yml", "generate consumer/producer handlers that are not whitelisted")
 	require.NoError(t, err)
@@ -398,8 +370,7 @@ func TestServer_Issue1557(t *testing.T) {
 }
 
 func TestServer_Issue1648(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	gen, err := testAppGenerator(t, "../fixtures/bugs/1648/fixture-1648.yaml", "generate format with missing type in model")
 	require.NoError(t, err)
@@ -409,34 +380,38 @@ func TestServer_Issue1648(t *testing.T) {
 }
 
 func TestServer_Issue1746(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
+	defer discardOutput()()
+
 	targetdir, err := ioutil.TempDir(".", "swagger_server")
 	require.NoErrorf(t, err, "failed to create a test target directory: %v", err)
-	err = os.Chdir(targetdir)
-	require.NoErrorf(t, err, "failed to create a test target directory: %v", err)
 	defer func() {
-		log.SetOutput(os.Stdout)
-		_ = os.Chdir("..")
 		_ = os.RemoveAll(targetdir)
 	}()
 
-	opts := testGenOpts()
+	cwd := testCwd(t)
+	require.NoErrorf(t, os.Chdir(targetdir), "failed to create a test target directory: %v", err)
+	defer func() {
+		_ = os.Chdir(cwd)
+	}()
 
+	opts := testGenOpts()
 	opts.Target = filepath.Join("x")
-	_ = os.Mkdir(opts.Target, 0755)
 	opts.Spec = filepath.Join("..", "..", "fixtures", "bugs", "1746", "fixture-1746.yaml")
 	tgtSpec := regexp.QuoteMeta(filepath.Join("..", "..", opts.Spec))
 
-	err = GenerateServer("", nil, nil, opts)
-	require.NoError(t, err)
+	require.NoError(t, os.Mkdir(opts.Target, 0755))
+
+	require.NoError(t, GenerateServer("", nil, nil, opts))
 
 	gulp, err := ioutil.ReadFile(filepath.Join("x", "restapi", "configure_example_swagger_server.go"))
 	require.NoError(t, err)
 
+	res := string(gulp)
+
 	tgtPath := regexp.QuoteMeta(filepath.Join("..", "..", opts.Target))
-	assertRegexpInCode(t, `go:generate swagger generate server.+\-\-target `+tgtPath, string(gulp))
-	assertRegexpInCode(t, `go:generate swagger generate server.+\-\-name\s+ExampleSwaggerServer`, string(gulp))
-	assertRegexpInCode(t, `go:generate swagger generate server.+\-\-spec\s+`+tgtSpec, string(gulp))
+	assertRegexpInCode(t, `go:generate swagger generate server.+\-\-target `+tgtPath, res)
+	assertRegexpInCode(t, `go:generate swagger generate server.+\-\-name\s+ExampleSwaggerServer`, res)
+	assertRegexpInCode(t, `go:generate swagger generate server.+\-\-spec\s+`+tgtSpec, res)
 }
 
 func doGenAppTemplate(t testing.TB, fixture, template string) string {
@@ -456,8 +431,7 @@ func doGenAppTemplate(t testing.TB, fixture, template string) string {
 }
 
 func TestServer_Issue1816(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer log.SetOutput(os.Stdout)
+	defer discardOutput()()
 
 	// fixed regression: gob encoding in $ref
 	res := doGenAppTemplate(t, "../fixtures/bugs/1816/fixture-1816.yaml", "swaggerJsonEmbed")
diff --git a/generator/shared_test.go b/generator/shared_test.go
index a19d782e..815f3bf2 100644
--- a/generator/shared_test.go
+++ b/generator/shared_test.go
@@ -131,7 +131,7 @@ func TestShared_CheckOpts(t *testing.T) {
 
 func TestShared_EnsureDefaults(t *testing.T) {
 	opts := &GenOpts{}
-	_ = opts.EnsureDefaults()
+	require.NoError(t, opts.EnsureDefaults())
 	assert.True(t, opts.defaultsEnsured)
 	opts.DefaultConsumes = "https"
 	_ = opts.EnsureDefaults()
@@ -276,7 +276,7 @@ func TestShared_NotFoundTemplate(t *testing.T) {
 	log.SetOutput(ioutil.Discard)
 	defer log.SetOutput(os.Stdout)
 
-	opts := GenOpts{}
+	opts := testGenOpts()
 	tplOpts := TemplateOpts{
 		Name:       "NotFound",
 		Source:     "asset:notfound",
@@ -287,8 +287,8 @@ func TestShared_NotFoundTemplate(t *testing.T) {
 	}
 
 	buf, err := opts.render(&tplOpts, nil)
-	assert.Error(t, err, "Error should be handled here")
-	assert.Nil(t, buf, "Upon error, GenOpts.render() should return nil buffer")
+	require.Errorf(t, err, "Error should be handled here")
+	assert.Nilf(t, buf, "Upon error, GenOpts.render() should return nil buffer")
 }
 
 // Low level testing: invalid template => Get() returns not found (higher level calls raise panic(), see above)
@@ -300,7 +300,8 @@ func TestShared_GarbledTemplate(t *testing.T) {
 	garbled := "func x {{;;; garbled"
 
 	_ = templates.AddFile("garbled", garbled)
-	opts := GenOpts{}
+	opts := testGenOpts()
+
 	tplOpts := TemplateOpts{
 		Name:       "Garbled",
 		Source:     "asset:garbled",
@@ -311,8 +312,8 @@ func TestShared_GarbledTemplate(t *testing.T) {
 	}
 
 	buf, err := opts.render(&tplOpts, nil)
-	assert.Error(t, err, "Error should be handled here")
-	assert.Nil(t, buf, "Upon error, GenOpts.render() should return nil buffer")
+	require.Errorf(t, err, "Error should be handled here")
+	assert.Nilf(t, buf, "Upon error, GenOpts.render() should return nil buffer")
 }
 
 // Template execution failure
@@ -331,7 +332,8 @@ func TestShared_ExecTemplate(t *testing.T) {
 	execfailure1 := "func x {{ .NotInData }}"
 
 	_ = templates.AddFile("execfailure1", execfailure1)
-	opts := new(GenOpts)
+	opts := testGenOpts()
+
 	tplOpts := TemplateOpts{
 		Name:       "execFailure1",
 		Source:     "asset:execfailure1",
@@ -348,7 +350,7 @@ func TestShared_ExecTemplate(t *testing.T) {
 	execfailure2 := "func {{ .MyFaultyMethod }}"
 
 	_ = templates.AddFile("execfailure2", execfailure2)
-	opts = new(GenOpts)
+	opts = testGenOpts()
 	tplOpts2 := TemplateOpts{
 		Name:       "execFailure2",
 		Source:     "asset:execfailure2",
@@ -382,7 +384,7 @@ func TestShared_BadFormatTemplate(t *testing.T) {
 	Debug = true
 	_ = templates.AddFile("badformat", badFormat)
 
-	opts := GenOpts{}
+	opts := testGenOpts()
 	opts.LanguageOpts = GoLangOpts()
 	tplOpts := TemplateOpts{
 		Name:   "badformat",
@@ -400,17 +402,19 @@ func TestShared_BadFormatTemplate(t *testing.T) {
 	}
 
 	err := opts.write(&tplOpts, data)
+	defer func() {
+		_ = os.Remove(tplOpts.FileName)
+	}()
 
 	// The badly formatted file has been dumped for debugging purposes
 	_, exists := os.Stat(tplOpts.FileName)
 	assert.True(t, !os.IsNotExist(exists), "The template file has not been generated as expected")
-	_ = os.Remove(tplOpts.FileName)
 
-	assert.NotNil(t, err)
+	require.Error(t, err)
 	assert.Contains(t, err.Error(), "source formatting on generated source")
 
 	// Skipping format
-	opts = GenOpts{}
+	opts = testGenOpts()
 	opts.LanguageOpts = GoLangOpts()
 	tplOpts2 := TemplateOpts{
 		Name:       "badformat2",
@@ -447,7 +451,7 @@ func TestShared_DirectoryTemplate(t *testing.T) {
 
 	_ = templates.AddFile("gendir", content)
 
-	opts := GenOpts{}
+	opts := testGenOpts()
 	opts.LanguageOpts = GoLangOpts()
 	tplOpts := TemplateOpts{
 		Name:   "gendir",
@@ -480,7 +484,7 @@ func TestShared_LoadTemplate(t *testing.T) {
 	log.SetOutput(ioutil.Discard)
 	defer log.SetOutput(os.Stdout)
 
-	opts := GenOpts{}
+	opts := testGenOpts()
 	tplOpts := TemplateOpts{
 		Name:       "File",
 		Source:     "File",
diff --git a/generator/support_test.go b/generator/support_test.go
index a2be5406..a253c41f 100644
--- a/generator/support_test.go
+++ b/generator/support_test.go
@@ -121,8 +121,7 @@ func TestBaseImport(t *testing.T) {
 
 		// Create Paths
 		for _, paths := range item.path {
-			err = os.MkdirAll(paths, 0700)
-			require.NoError(t, err)
+			require.NoError(t, os.MkdirAll(paths, 0700))
 		}
 
 		if item.symlinksrc == "" {
@@ -130,8 +129,7 @@ func TestBaseImport(t *testing.T) {
 		}
 
 		// Create Symlink
-		err := os.Symlink(item.symlinkdest, item.symlinksrc)
-		require.NoErrorf(t, err,
+		require.NoErrorf(t, os.Symlink(item.symlinkdest, item.symlinksrc),
 			"WARNING:TestBaseImport with symlink could not be carried on. Symlink creation failed for %s -> %s: %v\n%s",
 			item.symlinksrc, item.symlinkdest, err,
 			"NOTE:TestBaseImport with symlink on Windows requires extended privileges (admin or a user with SeCreateSymbolicLinkPrivilege)",
diff --git a/generator/types_test.go b/generator/types_test.go
index 3a43b8d4..e26cd3cf 100644
--- a/generator/types_test.go
+++ b/generator/types_test.go
@@ -2,9 +2,6 @@ package generator
 
 import (
 	"encoding/json"
-	"io/ioutil"
-	"log"
-	"os"
 	"strconv"
 	"testing"
 
@@ -328,10 +325,7 @@ func makeResolveExternalTypes() []externalTypeFixture {
 }
 
 func TestShortCircuitResolveExternal(t *testing.T) {
-	log.SetOutput(ioutil.Discard)
-	defer func() {
-		log.SetOutput(os.Stdout)
-	}()
+	defer discardOutput()()
 
 	for i, toPin := range makeResolveExternalTypes() {
 		fixture := toPin
@@ -354,6 +348,7 @@ func TestShortCircuitResolveExternal(t *testing.T) {
 			extType, ok := hasExternalType(schema.Extensions)
 			require.Truef(t, ok, "fixture %d", i)
 			require.NotNil(t, extType)
+			//require.EqualValues(t, fixture.expected, extType) // TODO(fred)
 
 			tpe, pkg, alias := r.knownDefGoType("A", schema, r.goTypeName)
 			require.EqualValuesf(t, fixture.knownDefs, struct{ tpe, pkg, alias string }{tpe, pkg, alias}, "fixture %d", i)
diff --git a/generator/utils_test.go b/generator/utils_test.go
new file mode 100644
index 00000000..b6b1050b
--- /dev/null
+++ b/generator/utils_test.go
@@ -0,0 +1,95 @@
+package generator
+
+import (
+	"io/ioutil"
+	"log"
+	"os"
+	"os/exec"
+	"regexp"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+)
+
+// testing utilities for codegen assertions
+
+func reqm(str string) *regexp.Regexp {
+	return regexp.MustCompile(regexp.QuoteMeta(str))
+}
+
+func reqOri(str string) *regexp.Regexp {
+	return regexp.MustCompile(str)
+}
+
+func assertInCode(t testing.TB, expr, code string) bool {
+	return assert.Regexp(t, reqm(expr), code)
+}
+
+func assertRegexpInCode(t testing.TB, expr, code string) bool {
+	return assert.Regexp(t, reqOri(expr), code)
+}
+
+func assertNotInCode(t testing.TB, expr, code string) bool {
+	return assert.NotRegexp(t, reqm(expr), code)
+}
+
+// Unused
+// func assertRegexpNotInCode(t testing.TB, expr, code string) bool {
+// 	return assert.NotRegexp(t, reqOri(expr), code)
+// }
+
+func requireValidation(t testing.TB, pth, expr string, gm GenSchema) {
+	if !assertValidation(t, pth, expr, gm) {
+		t.FailNow()
+	}
+}
+
+func assertValidation(t testing.TB, pth, expr string, gm GenSchema) bool {
+	if !assert.True(t, gm.HasValidations, "expected the schema to have validations") {
+		return false
+	}
+	if !assert.Equal(t, pth, gm.Path, "paths don't match") {
+		return false
+	}
+	if !assert.Equal(t, expr, gm.ValueExpression, "expressions don't match") {
+		return false
+	}
+	return true
+}
+
+func funcBody(code string, signature string) string {
+	submatches := regexp.MustCompile(
+		"\\nfunc \\([a-zA-Z_][a-zA-Z0-9_]* " + regexp.QuoteMeta(signature) + " {\\n" + // function signature
+			"((([^}\\n][^\\n]*)?\\n)*)}\\n", // function body
+	).FindStringSubmatch(code)
+
+	if submatches == nil {
+		return ""
+	}
+	return submatches[1]
+}
+
+// testing utilities for codegen build
+
+func goExecInDir(t testing.TB, target string, args ...string) {
+	cmd := exec.Command("go", args...)
+	cmd.Dir = target
+	p, err := cmd.CombinedOutput()
+	require.NoErrorf(t, err, "unexpected error: %s: %v\n%s", cmd.String(), err, string(p))
+}
+
+func testCwd(t testing.TB) string {
+	cwd, err := os.Getwd()
+	require.NoError(t, err)
+	return cwd
+}
+
+func discardOutput() func() {
+	// discards log output then sends a function to set it back to stdout
+	log.SetOutput(ioutil.Discard)
+
+	return func() {
+		log.SetOutput(os.Stdout)
+	}
+}