(self)
| 35 | |
| 36 | |
| 37 | def __enter__(self): |
| 38 | if self._port is None: |
| 39 | self.port = get_random_port() |
| 40 | else: |
| 41 | self.port = self._port |
| 42 | args = [self.path, |
| 43 | '--port', str(self.port), |
| 44 | '--dir', tempfile.gettempdir(), |
| 45 | '--save', ''] + self.extra_args |
| 46 | |
| 47 | self.process = subprocess.Popen( |
| 48 | args, |
| 49 | #cwd=os.getcwd(), |
| 50 | stdin=subprocess.PIPE, |
| 51 | stdout=open(os.devnull, 'w') |
| 52 | ) |
| 53 | |
| 54 | while True: |
| 55 | try: |
| 56 | self.client().ping() |
| 57 | |
| 58 | break |
| 59 | except redis.ConnectionError: |
| 60 | self.process.poll() |
| 61 | if self.process.returncode is not None: |
| 62 | raise RuntimeError("Process has exited") |
| 63 | time.sleep(0.1) |
| 64 | |
| 65 | return self.client() |
| 66 | |
| 67 | def __exit__(self, exc_type, exc_val, exc_tb): |
| 68 | self.process.terminate() |
nothing calls this directly
no test coverage detected