Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 带Selenium集线器的Bitbucket管道不工作?让它在本地与docker一起工作_Python_Docker_Continuous Integration_Bitbucket_Bitbucket Pipelines - Fatal编程技术网

Python 带Selenium集线器的Bitbucket管道不工作?让它在本地与docker一起工作

Python 带Selenium集线器的Bitbucket管道不工作?让它在本地与docker一起工作,python,docker,continuous-integration,bitbucket,bitbucket-pipelines,Python,Docker,Continuous Integration,Bitbucket,Bitbucket Pipelines,我已经尝试在本地复制bitbucket管道构建,并且可以让它正常工作,因此我的集成测试正在运行,并通过Docker。然而,一旦我推到Bitbucket,这些测试就会失败 我想答案很简单——我就是想不出来 这是一个Django项目/应用程序,我使用Selenium启动firefox和chrome浏览器进行测试 我有以下docker-compose.yml,它在本地工作: version: "3.3" services: python: image: "ha

我已经尝试在本地复制bitbucket管道构建,并且可以让它正常工作,因此我的集成测试正在运行,并通过Docker。然而,一旦我推到Bitbucket,这些测试就会失败

我想答案很简单——我就是想不出来

这是一个Django项目/应用程序,我使用Selenium启动firefox和chrome浏览器进行测试

我有以下docker-compose.yml,它在本地工作:

version: "3.3"
services:
  python:
    image: "hanny/python:3.8"
    build:
      context: ./docker
      dockerfile: python.dock
    volumes:
      - ".:/project_dir"
    environment:
      - DJANGO_DEBUG=True
      - myproject_SECRET_KEY=1234_secret_key_4321
      - BITBUCKET_CI=True
    ports:
      - "8000:8000"
    links:
      - hub
  firefox:
    image: selenium/node-firefox
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - hub
    environment:
      HUB_HOST: hub
  chrome:
    image: selenium/node-chrome
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - hub
    environment:
      HUB_HOST: hub
  hub:
    image: selenium/hub
    ports:
      - "4444:4444"
python.dock文件非常简单:

FROM python:3.8
SHELL ["/bin/bash", "-c"]

RUN pip install virtualenv

CMD ["tail", "-F", "-n0", "/etc/hosts"]
然后,我为该容器启动一个交互式bashshell,安装需求并运行pytest

我的bitbucket-pipelines.yml文件也非常简单/直接:

image: python:3.8

pipelines:
  branches:
    dev:
      - step:
          name: Build project & run pytest
          caches:
            - pip
          services:
            - hub
          script: # Modify the commands below to build your repository.
            - pip install virtualenv
            - virtualenv venv
            - source venv/bin/activate
            - apt-get install gcc libc-dev g++ libffi-dev libxml2 unixodbc-dev gnupg2 -y
            - pip install -r requirements-dev.txt
            - pytest
definitions:
  services:
    firefox:
      image: selenium/node-firefox
      volumes:
        - /dev/shm:/dev/shm
      depends_on:
        - hub
      environment:
        HUB_HOST: hub
    chrome:
      image: selenium/node-chrome
      volumes:
        - /dev/shm:/dev/shm
      depends_on:
        - hub
      environment:
        HUB_HOST: hub
    hub:
      image: selenium/hub
      ports:
        - "4444:4444"
我使用pytest进行测试,在测试浏览器的设置中,它如下所示:

    HUB_URL = "http://hub:4444/wd/hub"
    chrome_capabilities = DesiredCapabilities.CHROME.copy()
    browser = webdriver.Remote(
        command_executor=HUB_URL, desired_capabilities=chrome_capabilities
    )
这将启动相应的浏览器,并且我的测试全部通过,在本地使用Docker没有问题。我相信这是因为我使用链接将这两个容器彼此连接在一起,这样我就可以在URL中使用服务名称,并对其进行适当的路由

当我在Bitbucket上运行CI时,测试失败

这是失败消息:

        try:
>           conn = connection.create_connection(
                (self._dns_host, self.port), self.timeout, **extra_kw
            )
venv/lib/python3.8/site-packages/urllib3/connection.py:159: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
address = ('hub', 4444), timeout = <object object at 0x7f8bd0757630>
source_address = None, socket_options = [(6, 1, 1)]
    def create_connection(
        address,
        timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
        source_address=None,
        socket_options=None,
    ):
        """Connect to *address* and return the socket object.
    
        Convenience function.  Connect to *address* (a 2-tuple ``(host,
        port)``) and return the socket object.  Passing the optional
        *timeout* parameter will set the timeout on the socket instance
        before attempting to connect.  If no *timeout* is supplied, the
        global default timeout setting returned by :func:`getdefaulttimeout`
        is used.  If *source_address* is set it must be a tuple of (host, port)
        for the socket to bind as a source address before making the connection.
        An host of '' or port 0 tells the OS to use the default.
        """
    
        host, port = address
        if host.startswith("["):
            host = host.strip("[]")
        err = None
    
        # Using the value from allowed_gai_family() in the context of getaddrinfo lets
        # us select whether to work with IPv4 DNS records, IPv6 records, or both.
我相信这与使用http://hub:4444/wd/hub 作为URL

在管道中,我应该为该URL使用什么?我尝试了localhost和127.0.0.1,但没有成功

我正在使用Docker尝试在本地复制Pipelines环境,这样,如果没有必要,我就不会花几分钟的时间。但现在它在本地工作——我不知道如何在Bitbucket管道中运行它