Skip to content

Commit 03b0d19

Browse files
inconstanteyedayak
authored andcommitted
test(unit): add missing dependency on fixtures to help parallel testing
When running the test suite with xdist and 'pytest -n <jobs>', several tests fail. This happens because, in these tests, the definition of the tested command, usually in a fixture method called 'functions' might happen only after the execution of the tests themselves, i.e. in the methods whose names start with 'test_'. This patch adds the missing dependency on these test-command-defining fixtures, so that they are executed before the tests themselves. Steps to reproduce: 1. Make sure pytest-xdist is installed. On Debian systems this can be verified with the following command: dpkg --list python3-pytest-xdist 2. Build and install bash-completion locally, for example with the following commands: autoreconf -f -i ./configure --prefix=$PWD/install/ make install 3. Run the test suite with a few parallel jobs, such as with: export MYPATH=$PWD/install/share/bash-completion/bash_completion BASH_COMPLETION_TEST_BASH_COMPLETION=$MYPATH \ pytest \ -n 8 \ test/t/unit/test_unit_count_args.py \ test/t/unit/test_unit_dequote.py \ test/t/unit/test_unit_get_first_arg.py \ test/t/unit/test_unit_quote.py unset MYPATH Before this patch, these tests fail with messages similar to: FAILED test/t/unit/test_unit_quote.py::TestUnitQuote::test_3 - AssertionError: Error running "__tester " a "": exit status=127, output=" After this patch, all these tests, which previously failed, pass.
1 parent c7e6321 commit 03b0d19

File tree

4 files changed

+55
-49
lines changed

4 files changed

+55
-49
lines changed

test/t/unit/test_unit_count_args.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,38 +76,38 @@ def test_9(self, bash, functions):
7676
)
7777
assert output == "3"
7878

79-
def test_10_single_hyphen_1(self, bash):
79+
def test_10_single_hyphen_1(self, bash, functions):
8080
"""- should be counted as an argument representing stdout/stdin"""
8181
output = self._test(bash, "(a -b - c -d e)", 5, "a -b - c -d e", 12)
8282
assert output == "3"
8383

84-
def test_10_single_hyphen_2(self, bash):
84+
def test_10_single_hyphen_2(self, bash, functions):
8585
"""- in an option argument should be skipped"""
8686
output = self._test(
8787
bash, "(a -b - c - e)", 5, "a -b - c - e", 11, arg='-a "-b"'
8888
)
8989
assert output == "3"
9090

91-
def test_11_double_hyphen_1(self, bash):
91+
def test_11_double_hyphen_1(self, bash, functions):
9292
"""all the words after -- should be counted"""
9393
output = self._test(
9494
bash, "(a -b -- -c -d e)", 5, "a -b -- -c -d e", 14
9595
)
9696
assert output == "3"
9797

98-
def test_11_double_hyphen_2(self, bash):
98+
def test_11_double_hyphen_2(self, bash, functions):
9999
"""all the words after -- should be counted"""
100100
output = self._test(bash, "(a b -- -c -d e)", 5, "a b -- -c -d e", 13)
101101
assert output == "4"
102102

103-
def test_12_exclude_optarg_1(self, bash):
103+
def test_12_exclude_optarg_1(self, bash, functions):
104104
"""an option argument should be skipped even if it matches the argument pattern"""
105105
output = self._test(
106106
bash, "(a -o -x b c)", 4, "a -o -x b c", 10, arg='-a "-o" -i "-x"'
107107
)
108108
assert output == "2"
109109

110-
def test_12_exclude_optarg_2(self, bash):
110+
def test_12_exclude_optarg_2(self, bash, functions):
111111
"""an option argument should be skipped even if it matches the argument pattern"""
112112
output = self._test(
113113
bash,
@@ -119,7 +119,7 @@ def test_12_exclude_optarg_2(self, bash):
119119
)
120120
assert output == "2"
121121

122-
def test_12_exclude_optarg_3(self, bash):
122+
def test_12_exclude_optarg_3(self, bash, functions):
123123
"""an option argument should be skipped even if it matches the argument pattern"""
124124
output = self._test(
125125
bash,
@@ -131,21 +131,21 @@ def test_12_exclude_optarg_3(self, bash):
131131
)
132132
assert output == "1"
133133

134-
def test_13_plus_option_optarg(self, bash):
134+
def test_13_plus_option_optarg(self, bash, functions):
135135
"""When +o is specified to be an option taking an option argument, it should not be counted as an argument"""
136136
output = self._test(
137137
bash, "(a +o b c)", 3, "a +o b c", 7, arg='-a "+o"'
138138
)
139139
assert output == "1"
140140

141-
def test_14_no_optarg_chain_1(self, bash):
141+
def test_14_no_optarg_chain_1(self, bash, functions):
142142
"""an option argument should not take another option argument"""
143143
output = self._test(
144144
bash, "(a -o -o -o -o c)", 5, "a -o -o -o -o c", 14, arg='-a "-o"'
145145
)
146146
assert output == "1"
147147

148-
def test_14_no_optarg_chain_2(self, bash):
148+
def test_14_no_optarg_chain_2(self, bash, functions):
149149
"""an option argument should not take another option argument"""
150150
output = self._test(
151151
bash,
@@ -157,14 +157,14 @@ def test_14_no_optarg_chain_2(self, bash):
157157
)
158158
assert output == "2"
159159

160-
def test_15_double_hyphen_optarg(self, bash):
160+
def test_15_double_hyphen_optarg(self, bash, functions):
161161
"""-- should lose its meaning when it is an option argument"""
162162
output = self._test(
163163
bash, "(a -o -- -b -c d)", 5, "a -o -- -b -c d", 14, arg='-a "-o"'
164164
)
165165
assert output == "1"
166166

167-
def test_16_empty_word(self, bash):
167+
def test_16_empty_word(self, bash, functions):
168168
"""An empty word should not take an option argument"""
169169
output = self._test(bash, "(a '' x '' y d)", 5, "a x y d", 8)
170170
assert output == "5"

test/t/unit/test_unit_dequote.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,123 +9,126 @@
99
ignore_env=r"^\+declare -f __tester$",
1010
)
1111
class TestDequote:
12-
def test_1_char(self, bash):
12+
@pytest.fixture
13+
def functions(self, bash):
1314
assert_bash_exec(
1415
bash,
1516
'__tester() { local REPLY=dummy v=var;_comp_dequote "$1";local ext=$?;((${#REPLY[@]}))&&printf \'<%s>\' "${REPLY[@]}";echo;return $ext;}',
1617
)
18+
19+
def test_1_char(self, bash, functions):
1720
output = assert_bash_exec(bash, "__tester a", want_output=True)
1821
assert output.strip() == "<a>"
1922

20-
def test_2_str(self, bash):
23+
def test_2_str(self, bash, functions):
2124
output = assert_bash_exec(bash, "__tester abc", want_output=True)
2225
assert output.strip() == "<abc>"
2326

24-
def test_3_null(self, bash):
27+
def test_3_null(self, bash, functions):
2528
output = assert_bash_exec(bash, "__tester ''", want_output=True)
2629
assert output.strip() == ""
2730

28-
def test_4_empty(self, bash):
31+
def test_4_empty(self, bash, functions):
2932
output = assert_bash_exec(bash, "__tester \"''\"", want_output=True)
3033
assert output.strip() == "<>"
3134

32-
def test_5_brace(self, bash):
35+
def test_5_brace(self, bash, functions):
3336
output = assert_bash_exec(bash, "__tester 'a{1..3}'", want_output=True)
3437
assert output.strip() == "<a1><a2><a3>"
3538

36-
def test_6_glob(self, bash):
39+
def test_6_glob(self, bash, functions):
3740
output = assert_bash_exec(bash, "__tester 'a?b'", want_output=True)
3841
assert output.strip() == "<a b><a$b><a&b><a'b>"
3942

40-
def test_7_quote_1(self, bash):
43+
def test_7_quote_1(self, bash, functions):
4144
output = assert_bash_exec(
4245
bash, "__tester '\"a\"'\\'b\\'\\$\\'c\\'", want_output=True
4346
)
4447
assert output.strip() == "<abc>"
4548

46-
def test_7_quote_2(self, bash):
49+
def test_7_quote_2(self, bash, functions):
4750
output = assert_bash_exec(
4851
bash, "__tester '\\\"\\'\\''\\$\\`'", want_output=True
4952
)
5053
assert output.strip() == "<\"'$`>"
5154

52-
def test_7_quote_3(self, bash):
55+
def test_7_quote_3(self, bash, functions):
5356
output = assert_bash_exec(
5457
bash, "__tester \\$\\'a\\\\tb\\'", want_output=True
5558
)
5659
assert output.strip() == "<a\tb>"
5760

58-
def test_7_quote_4(self, bash):
61+
def test_7_quote_4(self, bash, functions):
5962
output = assert_bash_exec(
6063
bash, '__tester \'"abc\\"def"\'', want_output=True
6164
)
6265
assert output.strip() == '<abc"def>'
6366

64-
def test_7_quote_5(self, bash):
67+
def test_7_quote_5(self, bash, functions):
6568
output = assert_bash_exec(
6669
bash, "__tester \\'abc\\'\\\\\\'\\'def\\'", want_output=True
6770
)
6871
assert output.strip() == "<abc'def>"
6972

70-
def test_8_param_1(self, bash):
73+
def test_8_param_1(self, bash, functions):
7174
output = assert_bash_exec(bash, "__tester '$v'", want_output=True)
7275
assert output.strip() == "<var>"
7376

74-
def test_8_param_2(self, bash):
77+
def test_8_param_2(self, bash, functions):
7578
output = assert_bash_exec(bash, "__tester '${v}'", want_output=True)
7679
assert output.strip() == "<var>"
7780

78-
def test_8_param_3(self, bash):
81+
def test_8_param_3(self, bash, functions):
7982
output = assert_bash_exec(bash, "__tester '${#v}'", want_output=True)
8083
assert output.strip() == "<3>"
8184

82-
def test_8_param_4(self, bash):
85+
def test_8_param_4(self, bash, functions):
8386
output = assert_bash_exec(bash, "__tester '${v[0]}'", want_output=True)
8487
assert output.strip() == "<var>"
8588

86-
def test_9_qparam_1(self, bash):
89+
def test_9_qparam_1(self, bash, functions):
8790
output = assert_bash_exec(bash, "__tester '\"$v\"'", want_output=True)
8891
assert output.strip() == "<var>"
8992

90-
def test_9_qparam_2(self, bash):
93+
def test_9_qparam_2(self, bash, functions):
9194
output = assert_bash_exec(
9295
bash, "__tester '\"${v[@]}\"'", want_output=True
9396
)
9497
assert output.strip() == "<var>"
9598

96-
def test_10_pparam_1(self, bash):
99+
def test_10_pparam_1(self, bash, functions):
97100
output = assert_bash_exec(bash, "__tester '$?'", want_output=True)
98101
assert output.strip() == "<0>"
99102

100-
def test_10_pparam_2(self, bash):
103+
def test_10_pparam_2(self, bash, functions):
101104
output = assert_bash_exec(bash, "__tester '${#1}'", want_output=True)
102105
assert output.strip() == "<5>" # The string `${#1}` is five characters
103106

104-
def test_unsafe_1(self, bash):
107+
def test_unsafe_1(self, bash, functions):
105108
output = assert_bash_exec(
106109
bash, "! __tester '$(echo hello >&2)'", want_output=True
107110
)
108111
assert output.strip() == ""
109112

110-
def test_unsafe_2(self, bash):
113+
def test_unsafe_2(self, bash, functions):
111114
output = assert_bash_exec(
112115
bash, "! __tester '|echo hello >&2'", want_output=True
113116
)
114117
assert output.strip() == ""
115118

116-
def test_unsafe_3(self, bash):
119+
def test_unsafe_3(self, bash, functions):
117120
output = assert_bash_exec(
118121
bash, "! __tester '>| important_file.txt'", want_output=True
119122
)
120123
assert output.strip() == ""
121124

122-
def test_unsafe_4(self, bash):
125+
def test_unsafe_4(self, bash, functions):
123126
output = assert_bash_exec(
124127
bash, "! __tester '`echo hello >&2`'", want_output=True
125128
)
126129
assert output.strip() == ""
127130

128-
def test_glob_default(self, bash):
131+
def test_glob_default(self, bash, functions):
129132
with bash_env_saved(bash) as bash_env:
130133
bash_env.shopt("failglob", False)
131134
bash_env.shopt("nullglob", False)
@@ -134,7 +137,7 @@ def test_glob_default(self, bash):
134137
)
135138
assert output.strip() == "<non-existent-*.txt>"
136139

137-
def test_glob_noglob(self, bash):
140+
def test_glob_noglob(self, bash, functions):
138141
with bash_env_saved(bash) as bash_env:
139142
bash_env.set("noglob", True)
140143
output = assert_bash_exec(
@@ -144,15 +147,15 @@ def test_glob_noglob(self, bash):
144147
)
145148
assert output.strip() == "<non-existent-*.txt>"
146149

147-
def test_glob_failglob(self, bash):
150+
def test_glob_failglob(self, bash, functions):
148151
with bash_env_saved(bash) as bash_env:
149152
bash_env.shopt("failglob", True)
150153
output = assert_bash_exec(
151154
bash, "! __tester 'non-existent-*.txt'", want_output=True
152155
)
153156
assert output.strip() == ""
154157

155-
def test_glob_nullglob(self, bash):
158+
def test_glob_nullglob(self, bash, functions):
156159
with bash_env_saved(bash) as bash_env:
157160
bash_env.shopt("failglob", False)
158161
bash_env.shopt("nullglob", True)

test/t/unit/test_unit_get_first_arg.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,22 @@ def test_9_skip_optarg_2(self, bash, functions):
6969
output = self._test(bash, "(a -b --foo d e f)", 5, '-a "@(-c|--foo)"')
7070
assert output == "e"
7171

72-
def test_9_skip_optarg_3(self, bash):
72+
def test_9_skip_optarg_3(self, bash, functions):
7373
output = self._test(bash, "(a -b - c d e)", 5, '-a "-b"')
7474
assert output == "c"
7575

76-
def test_9_skip_optarg_4(self, bash):
76+
def test_9_skip_optarg_4(self, bash, functions):
7777
output = self._test(bash, "(a -b -c d e f)", 5, '-a "-[bc]"')
7878
assert output == "d"
7979

80-
def test_9_skip_optarg_5(self, bash):
80+
def test_9_skip_optarg_5(self, bash, functions):
8181
output = self._test(bash, "(a +o b c d)", 4, '-a "+o"')
8282
assert output == "c"
8383

84-
def test_9_skip_optarg_6(self, bash):
84+
def test_9_skip_optarg_6(self, bash, functions):
8585
output = self._test(bash, "(a -o -o -o -o b c)", 6, '-a "-o"')
8686
assert output == "b"
8787

88-
def test_9_skip_optarg_7(self, bash):
88+
def test_9_skip_optarg_7(self, bash, functions):
8989
output = self._test(bash, "(a -o -- -b -c d e)", 6, '-a "-o"')
9090
assert output == "d"

test/t/unit/test_unit_quote.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,38 @@
88
ignore_env=r"^\+declare -f __tester$",
99
)
1010
class TestUnitQuote(TestUnitBase):
11-
def test_1(self, bash):
11+
@pytest.fixture
12+
def functions(self, bash):
1213
assert_bash_exec(
1314
bash,
1415
'__tester() { local REPLY; _comp_quote "$1"; printf %s "$REPLY"; }',
1516
)
17+
18+
def test_1(self, bash, functions):
1619
output = assert_bash_exec(
1720
bash, '__tester "a b"', want_output=True, want_newline=False
1821
)
1922
assert output.strip() == "'a b'"
2023

21-
def test_2(self, bash):
24+
def test_2(self, bash, functions):
2225
output = assert_bash_exec(
2326
bash, '__tester "a b"', want_output=True, want_newline=False
2427
)
2528
assert output.strip() == "'a b'"
2629

27-
def test_3(self, bash):
30+
def test_3(self, bash, functions):
2831
output = assert_bash_exec(
2932
bash, '__tester " a "', want_output=True, want_newline=False
3033
)
3134
assert output.strip() == "' a '"
3235

33-
def test_4(self, bash):
36+
def test_4(self, bash, functions):
3437
output = assert_bash_exec(
3538
bash, "__tester \"a'b'c\"", want_output=True, want_newline=False
3639
)
3740
assert output.strip() == r"'a'\''b'\''c'"
3841

39-
def test_5(self, bash):
42+
def test_5(self, bash, functions):
4043
output = assert_bash_exec(
4144
bash, '__tester "a\'"', want_output=True, want_newline=False
4245
)

0 commit comments

Comments
 (0)