Last active
April 28, 2020 10:39
-
-
Save ryanc414/36ceadae22e4418ae2e9c0732b57fc31 to your computer and use it in GitHub Desktop.
PyTest fixture examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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