forked from BoboTiG/python-mss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
57 lines (37 loc) · 1.18 KB
/
conftest.py
File metadata and controls
57 lines (37 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# coding: utf-8
from __future__ import print_function
import glob
import os
import pytest
import mss
def pytest_addoption(parser):
txt = 'Display to use (examples: ":0.1", ":0" [default])'
parser.addoption("--display", action="store", default=":0", help=txt)
def purge_files():
""" Remove all generated files from previous runs. """
for fname in glob.glob("*.png"):
print("Deleting {!r} ...".format(fname))
os.unlink(fname)
for fname in glob.glob("*.png.old"):
print("Deleting {!r} ...".format(fname))
os.unlink(fname)
@pytest.fixture(scope="module", autouse=True)
def before_tests(request):
request.addfinalizer(purge_files)
@pytest.fixture(scope="session")
def display(request):
return request.config.getoption("--display")
@pytest.fixture(scope="module")
def sct(display):
try:
# `display` keyword is only for GNU/Linux
return mss.mss(display=display)
except TypeError:
return mss.mss()
@pytest.fixture(scope="session")
def is_travis():
return "TRAVIS" in os.environ
@pytest.fixture(scope="session")
def raw():
with open("tests/res/monitor-1024x768.raw", "rb") as f:
yield f.read()