Skip to content

Instantly share code, notes, and snippets.

@ryanc414
Last active April 28, 2020 10:39
Show Gist options
  • Save ryanc414/36ceadae22e4418ae2e9c0732b57fc31 to your computer and use it in GitHub Desktop.
Save ryanc414/36ceadae22e4418ae2e9c0732b57fc31 to your computer and use it in GitHub Desktop.
PyTest fixture examples
package main
import (
"flag"
"fmt"
"html"
"net"
"net/http"
)
// Start an HTTP server listening on localhost. Exposes a single route at
// "/hello".
func main() {
portPtr := flag.Int("port", 0, "port number to bind to")
flag.Parse()
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
})
listenAddr := fmt.Sprintf("localhost:%d", *portPtr)
l, err := net.Listen("tcp", listenAddr)
if err != nil {
panic(err)
}
fmt.Printf("listening on http://%s\n", l.Addr().String())
http.Serve(l, nil)
}
@ryanc414
Copy link
Author

For anyone wondering, this gist and all of the test_app* gists are for a medium article I wrote to demonstrate how to use PyTest fixtures: https://medium.com/analytics-vidhya/pytest-fixtures-for-fun-and-profit-9109d5ac2895

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment