import unittest
import os
from subprocess import check_call
from sh import ls


mountpoint = '/tmp/spotifile_test_mount'
class SpotifileTestClass(unittest.TestCase):
	@classmethod
	def setUpClass(cls):
		if not os.path.exists(mountpoint):
			os.mkdir(mountpoint)

	@classmethod
	def tearDownClass(cls):
		if os.path.exists(mountpoint):
			os.rmdir(mountpoint)

	def setUp(self):
		check_call(['./spotifile', mountpoint])

	def tearDown(self):
		check_call(['fusermount', '-u', mountpoint])

	def test_ls(self):
		assert 'connection' in ls(mountpoint)

from nose import with_setup
import os
from os import path
from subprocess import check_call
from sh import ls, cat


mountpoint = '/tmp/spotifile_test_mount'

def fs_mount():
	if not path.exists(mountpoint):
		os.mkdir(mountpoint)
	check_call(['./spotifile', mountpoint])

def fs_unmount():
	check_call(['fusermount', '-u', mountpoint])
	if path.exists(mountpoint):
		os.rmdir(mountpoint)

@with_setup(fs_mount, fs_unmount)
def test_ls():
	assert 'connection' in ls(mountpoint)

@with_setup(fs_mount, fs_unmount)
def test_cat_connection():
	assert 'logged in' in cat(path.join(mountpoint, 'connection'))


use with_setup instead of setUp/tearDown