Я пытаюсь запустить pytest Test Framework с Docker. Однако при запуске контейнера я сталкиваюсь с приведенной ниже ошибкой.
______________________________________________________________________________________ ERROR collecting test session _______________________________________________________________________________________
/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py:440: in _importconftest
return self._conftestpath2mod[conftestpath]
E KeyError: local('/myapp/Source/conftest.py')
During handling of the above exception, another exception occurred:
/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py:446: in _importconftest
mod = conftestpath.pyimport()
/usr/local/lib/python3.7/site-packages/py/_path/local.py:701: in pyimport
__import__(modname)
<frozen importlib._bootstrap>:983: in _find_and_load
???
<frozen importlib._bootstrap>:967: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:677: in _load_unlocked
???
/usr/local/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:140: in exec_module
exec(co, module.__dict__)
Source/conftest.py:2: in <module>
from Drivers.chromedriver import driver
Drivers/chromedriver.py:5: in <module>
driver = webdriver.Chrome(chromedriver)
/usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py:73: in __init__
self.service.start()
/usr/local/lib/python3.7/site-packages/selenium/webdriver/common/service.py:76: in start
stdin=PIPE)
/usr/local/lib/python3.7/subprocess.py:775: in __init__
restore_signals, start_new_session)
/usr/local/lib/python3.7/subprocess.py:1522: in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
E OSError: [Errno 8] Exec format error: '/usr/local/bin/chromedriver'
During handling of the above exception, another exception occurred:
/usr/local/lib/python3.7/site-packages/py/_path/common.py:377: in visit
for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
/usr/local/lib/python3.7/site-packages/py/_path/common.py:418: in gen
dirs = self.optsort([p for p in entries
/usr/local/lib/python3.7/site-packages/py/_path/common.py:419: in <listcomp>
if p.check(dir=1) and (rec is None or rec(p))])
/usr/local/lib/python3.7/site-packages/_pytest/main.py:606: in _recurse
ihook = self.gethookproxy(dirpath)
/usr/local/lib/python3.7/site-packages/_pytest/main.py:424: in gethookproxy
my_conftestmodules = pm._getconftestmodules(fspath)
/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py:420: in _getconftestmodules
mod = self._importconftest(conftestpath)
/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py:454: in _importconftest
raise ConftestImportFailure(conftestpath, sys.exc_info())
E _pytest.config.ConftestImportFailure: (local('/myapp/Source/conftest.py'), (<class 'OSError'>, OSError(8, 'Exec format error'), <traceback object at 0x7fec384f53c8>))
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================= 1 error in 0.37s =========================================
Мой Dockerfile выглядит так:
FROM python:3.7.2
MAINTAINER arun
#RUN apt-get update
#RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils
# Install Chrome for Selenium
RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb
RUN dpkg -i /chrome.deb || apt-get install -yf
RUN rm /chrome.deb
# Install chromedriver for Selenium
RUN curl https://chromedriver.storage.googleapis.com/2.31/chromedriver_linux64.zip -o /usr/local/bin/chromedriver
RUN chmod +x /usr/local/bin/chromedriver
#install python dependencies
COPY requirements.txt requirements.txt
RUN pip install -r ./requirements.txt
ADD . /myapp
WORKDIR /myapp
CMD "pytest"
ENV PYTHONDONTWRITEBYTECODE=true
EXPOSE 8080
Docker -compose.yml, файл показан ниже
version: '3.1'
services:
test:
build: .
volumes:
- .:/myapp
stdin_open: true
tty: true
И require.txt как показано ниже
chromedriver==2.24.1
coverage==4.5.4
fixtures==3.0.0
html-testRunner==1.2
importlib-metadata==0.23
MarkupSafe==1.1.1
packaging==19.2
parse==1.11.1
parse-type==0.4.2
pbr==5.4.2
pi==0.1.2
pipenv==2018.11.26
pluggy==0.13.0
py==1.8.0
pyparsing==2.4.2
pyperclip==1.7.0
pytest==5.1.2
pytest-bdd==3.2.1
pytest-html==2.0.0
pytest-metadata==1.8.0
pytest-splinter==2.0.1
pytest-docker-fixtures
python-mimeparse==1.6.0
python-subunit==1.3.0
selenium==3.141.0
splinter==0.11.0
testtools==2.3.0
unittest2==1.1.0
urllib3==1.24.1
Flask==1.0.2
gunicorn==19.9.0
pytest-pep8
pytest-pythonpath
docker
Мой main.py такой же, как показано ниже
from selenium import webdriver
chromedriver = '/usr/local/bin/chromedriver'
driver = webdriver.Chrome(chromedriver)
driver.maximize_window()
Может кто-нибудь подсказать, чего здесь не хватает? Есть ли какая-то другая конфигурация, необходимая для запуска Selenium-pytest UI Automation Framework в контейнере Docker?
Примечание # Для создания изображения я использую docker-compose up
, а затем для создания контейнера docker-compose run test sh