Skip to content

Commit

Permalink
Merge pull request #6 from mdmintz/context-manager-format
Browse files Browse the repository at this point in the history
Add a context manager format
  • Loading branch information
mdmintz authored Feb 6, 2023
2 parents 8239041 + 3e5de78 commit cc5fe0a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ display.start()
display.stop()
```

### Or as a context manager:

```python
with Display(visible=0, size=(1440, 1880)):
# Run browser tests in a headless environment
...
```

## When to use:

If you need to run browser tests on a headless machine (such as a Linux backend), and you can't use a browser's headless mode (such as Chrome's headless mode), then this may help. For example, Chrome does not allow extensions in headless mode, so if you need to run automated tests on a headless Linux machine and you need to use Chrome extensions, then this will let you run those tests using a virtual display.
Expand Down
2 changes: 1 addition & 1 deletion sbvirtualdisplay/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# sbvirtualdisplay package
__version__ = "1.1.1"
__version__ = "1.2.0"
9 changes: 9 additions & 0 deletions sbvirtualdisplay/abstractdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ def stop(self):
self._clear_xauth()
return self

def __enter__(self):
"""Used by the :keyword:`with` statement"""
self.start()
return self

def __exit__(self, *exc_info):
"""Used by the :keyword:`with` statement"""
self.stop()

def _setup_xauth(self):
"""Set up the Xauthority file & the XAUTHORITY environment variable."""
handle, filename = tempfile.mkstemp(
Expand Down

0 comments on commit cc5fe0a

Please sign in to comment.