Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@pytest.fixture
def app():
app = App()
print("Starting app")
app.start()
yield app
print("Stopping app")
app.stop()
@pytest.fixture(scope="module")
def app():
app = App()
print("Starting app")
app.start()
yield app
print("Stopping app")
app.stop()
@ryanc414
ryanc414 / app.go
Last active April 28, 2020 10:39
PyTest fixture examples
package main
import (
"flag"
"fmt"
"html"
"net"
"net/http"
)
"""Example usage of pytest fixtures."""
import subprocess
import re
import pytest
import requests
class App:
# First test with the default port, then test using a fixed port
# number.
@pytest.fixture(scope="module", params=[None, 9999])
def app(request):
app = App(port=request.param)
print("Starting app")
app.start()
yield app
print("Stopping app")
app.stop()
class AppClient:
def __init__(self, app_addr):
self._app_addr = app_addr
def request(self, method, path):
return requests.request(method, f"{self._app_addr}{path}")
@pytest.fixture(scope="function")
def app_client(app):
@ryanc414
ryanc414 / process_json.go
Created September 24, 2020 19:33
Process a JSON file, in Go
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
"os"
)
@ryanc414
ryanc414 / lists.go
Created September 24, 2020 22:35
linked lists in Go
package main
import (
"fmt"
"container/list"
)
func main() {
l := list.New()
l.PushBack(2)
@ryanc414
ryanc414 / lists.rs
Created September 24, 2020 22:36
linked lists in Rust
use std::collections::LinkedList;
fn main() {
let mut list: LinkedList<u32> = LinkedList::new();
list.push_back(2);
list.push_back(3);
list.push_back(5);
list.push_back(7);
list.push_back(11);