def launch_django_application(self, test_case: TestCase): if not isinstance(test_case.attach, DjangoSettings): raise UnexpectedError( f'Django tests should have DjangoSettings class as an attach, ' f'found {type(test_case.attach)}') source = test_case.source_name if source is None or not len(source): source = 'manage' full_source = source.replace('.', os.sep) + '.py' full_path = os.path.abspath(full_source) if not os.path.exists(full_path): filename = os.path.basename(full_source) folder, file = runnable_searcher( file_filter=lambda _, f: f == filename) full_path = os.path.abspath(folder + os.sep + file) self.full_path = full_path self.port = self.__find_free_port(test_case.attach.tryout_ports) if test_case.attach.use_database: self.__prepare_database(test_case.attach.test_database) self.process = PopenWrapper(sys.executable, self.full_path, 'runserver', self.port, '--noreload') i: int = 100 search_phrase = 'Starting development server at' while i: if search_phrase in self.process.stdout: test_case.attach.port = self.port break i -= 1 if self.process.is_error_happened(): i = 0 else: sleep(0.1) else: stdout = self.process.stdout.strip() stderr = self.process.stderr.strip() error_info = f'Cannot start Django server because cannot find "{search_phrase}" in process\' output' if len(stdout): error_info += '\n\nstdout:\n' + stdout if len(stderr): error_info += '\n\nstderr:\n' + stderr raise ErrorWithFeedback(error_info)
def _init_by_nothing(self): folder, file = runnable_searcher(os.getcwd()) without_py = file[:-3] self._init_by_module(os.path.abspath(folder), without_py)