version: 2
workflows:
  version: 2
  test:
    jobs:
      - test-3.6
      - test-3.5
      - test-2.7
jobs:
  test-3.6: &test-template
    docker:
      - image: circleci/python:3.6
    working_directory: ~/repo
    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "setup.py" }}
          - v1-dependencies-
      - run:
          name: Install dependencies
          command: |
            pip install --user virtualenv
            $HOME/.local/bin/virtualenv venv
            . venv/bin/activate
            pip install -e .[dev]
      - save_cache:
          paths:
            - ./venv
          key: v1-dependencies-{{ checksum "setup.py" }}
      - run:
          name: Run tests
          command: |
            . venv/bin/activate
            pytest
  test-3.5:
    <<: *test-template
    docker:
      - image: circleci/python:3.5
  test-2.7:
    <<: *test-template
    docker:
      - image: circleci/python:2.7

version: 2
workflows:
  version: 2
  test:
    jobs:
      - test-3.6
      - test-3.5
      - test-2.7
jobs:
  test-3.6: &test-template
    docker:
      - image: circleci/python:3.6
    working_directory: ~/repo
    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "setup.py" }}
          - v1-dependencies-
      - run:
          name: Install dependencies
          command: |
            python -m venv venv || virtualenv venv
            . venv/bin/activate
            pip install -e .[dev]
      - save_cache:
          paths:
            - ./venv
          key: v1-dependencies-{{ checksum "setup.py" }}
      - run:
          name: Run tests
          command: |
            . venv/bin/activate
            pytest
  test-3.5:
    <<: *test-template
    docker:
      - image: circleci/python:3.5
  test-2.7:
    <<: *test-template
    docker:
      - image: circleci/python:2.7

Use venv on py3 and preinstalled virtualenv on py2
Use venv on py3 and preinstalled virtualenv on py2
