# Dynamically scoped variables in Go

DevFeed: [Dynamically scoped variables in Go](<https://devfeed.tech/articles/dynamically-scoped-variables-in-go-20825.md>)

Original publisher: [Read original article](<https://dave.cheney.net/2019/12/08/dynamically-scoped-variables-in-go>)

Author: Dave Cheney

Published: 2019-12-08T01:36:27Z

Content type: tutorial

Language: en

Sources: [Dave Cheney](<https://devfeed.tech/sources/dave-cheney.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Unit testing](<https://devfeed.tech/topics/unit-testing.md>), [Testing](<https://devfeed.tech/topics/testing.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [go](<https://devfeed.tech/tags/go.md>), [small-ideas](<https://devfeed.tech/tags/small-ideas.md>), [testing](<https://devfeed.tech/tags/testing.md>), [unit-testing](<https://devfeed.tech/tags/unit-testing.md>)

## AI overview

This article explores a Go unit-testing problem involving repetitive assertions and the need to pass testing context through helper calls. It presents dynamic scoping as a thought experiment and describes how stack traces and pointer parsing can be used to emulate it in restricted cases.

## Source excerpt

This is a thought experiment in API design. It starts with the classic Go unit testing idiom: func TestOpenFile(t *testing.T) { f, err := os.Open("notfound") if err != nil { t.Fatal(err) } // ... } What's the problem with this code? The assertion. if err != nil { ... } is repetitive and in the [...]