File: conftest.py

package info (click to toggle)
fabric 2.6.0-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 932 kB
  • sloc: python: 4,064; makefile: 8
file content (31 lines) | stat: -rw-r--r-- 1,074 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# flake8: noqa
from fabric.testing.fixtures import client, remote, sftp, sftp_objs, transfer

from os.path import isfile, expanduser

from pytest import fixture

from mock import patch


# TODO: does this want to end up in the public fixtures module too?
@fixture(autouse=True)
def no_user_ssh_config():
    """
    Cowardly refuse to ever load what looks like user SSH config paths.

    Prevents the invoking user's real config from gumming up test results or
    inflating test runtime (eg if it sets canonicalization on, which will incur
    DNS lookups for nearly all of this suite's bogus names).
    """
    # An ugly, but effective, hack. I am not proud. I also don't see anything
    # that's >= as bulletproof and less ugly?
    # TODO: ideally this should expand to cover system config paths too, but
    # that's even less likely to be an issue.
    def no_config_for_you(path):
        if path == expanduser("~/.ssh/config"):
            return False
        return isfile(path)

    with patch("fabric.config.os.path.isfile", no_config_for_you):
        yield