assert os.path.isfile only working with full path
up vote
1
down vote
favorite
I've been given an educational assignment during which I write Gherkin scenarios to test a website using Python 3.6, Splinter and Behave. I'm making some pretty good progress but I'm stuck on this little thing. Currently I've succeeded in getting a file to download through a headless instance of Chrome in Ubuntu. However, for the last step of the scenario to pass, I need to verify the file's existence. After a lot of searching I've found a method that works, which is:
assert os.path.isfile('/home/[USERNAME]/Downloads/file.csv')
However, in order to make this test more compatible with other computers, I'd like the path to the file to be shorter and simpler. Most importantly, not using this system's username.
I'm new to all of this so this could very well be a dumb question, but I've been searching all over the place and I simply can't find an answer.
python splinter
New contributor
add a comment |
up vote
1
down vote
favorite
I've been given an educational assignment during which I write Gherkin scenarios to test a website using Python 3.6, Splinter and Behave. I'm making some pretty good progress but I'm stuck on this little thing. Currently I've succeeded in getting a file to download through a headless instance of Chrome in Ubuntu. However, for the last step of the scenario to pass, I need to verify the file's existence. After a lot of searching I've found a method that works, which is:
assert os.path.isfile('/home/[USERNAME]/Downloads/file.csv')
However, in order to make this test more compatible with other computers, I'd like the path to the file to be shorter and simpler. Most importantly, not using this system's username.
I'm new to all of this so this could very well be a dumb question, but I've been searching all over the place and I simply can't find an answer.
python splinter
New contributor
Did you try to use "os.path.realpath(file)" to get the real path for your file?
– F.Lira
Nov 8 at 10:51
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I've been given an educational assignment during which I write Gherkin scenarios to test a website using Python 3.6, Splinter and Behave. I'm making some pretty good progress but I'm stuck on this little thing. Currently I've succeeded in getting a file to download through a headless instance of Chrome in Ubuntu. However, for the last step of the scenario to pass, I need to verify the file's existence. After a lot of searching I've found a method that works, which is:
assert os.path.isfile('/home/[USERNAME]/Downloads/file.csv')
However, in order to make this test more compatible with other computers, I'd like the path to the file to be shorter and simpler. Most importantly, not using this system's username.
I'm new to all of this so this could very well be a dumb question, but I've been searching all over the place and I simply can't find an answer.
python splinter
New contributor
I've been given an educational assignment during which I write Gherkin scenarios to test a website using Python 3.6, Splinter and Behave. I'm making some pretty good progress but I'm stuck on this little thing. Currently I've succeeded in getting a file to download through a headless instance of Chrome in Ubuntu. However, for the last step of the scenario to pass, I need to verify the file's existence. After a lot of searching I've found a method that works, which is:
assert os.path.isfile('/home/[USERNAME]/Downloads/file.csv')
However, in order to make this test more compatible with other computers, I'd like the path to the file to be shorter and simpler. Most importantly, not using this system's username.
I'm new to all of this so this could very well be a dumb question, but I've been searching all over the place and I simply can't find an answer.
python splinter
python splinter
New contributor
New contributor
New contributor
asked Nov 8 at 10:42
Vitz
82
82
New contributor
New contributor
Did you try to use "os.path.realpath(file)" to get the real path for your file?
– F.Lira
Nov 8 at 10:51
add a comment |
Did you try to use "os.path.realpath(file)" to get the real path for your file?
– F.Lira
Nov 8 at 10:51
Did you try to use "os.path.realpath(file)" to get the real path for your file?
– F.Lira
Nov 8 at 10:51
Did you try to use "os.path.realpath(file)" to get the real path for your file?
– F.Lira
Nov 8 at 10:51
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
You could rewrite the path using the ~
which replaces /home/[USERNAME]/
, so it would become ~/Downloads/file.csv
. Then, you could use Python's os.path.expanduser()
function as follows:
assert os.path.isfile(os.path.expanduser('~/Downloads/file.csv'))
os.path.expanderuser()
will automatically expand it to /home/[USERNAME]/
for you.
1
Thank you! I knew I was very close having tried multiple os.path options, but this I hadn't yet. Works like a charm.
– Vitz
Nov 8 at 10:55
add a comment |
up vote
0
down vote
If you need to get Downloads folder path, than you can use answer to this question: python - Finding the user's "Downloads" folder
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You could rewrite the path using the ~
which replaces /home/[USERNAME]/
, so it would become ~/Downloads/file.csv
. Then, you could use Python's os.path.expanduser()
function as follows:
assert os.path.isfile(os.path.expanduser('~/Downloads/file.csv'))
os.path.expanderuser()
will automatically expand it to /home/[USERNAME]/
for you.
1
Thank you! I knew I was very close having tried multiple os.path options, but this I hadn't yet. Works like a charm.
– Vitz
Nov 8 at 10:55
add a comment |
up vote
0
down vote
accepted
You could rewrite the path using the ~
which replaces /home/[USERNAME]/
, so it would become ~/Downloads/file.csv
. Then, you could use Python's os.path.expanduser()
function as follows:
assert os.path.isfile(os.path.expanduser('~/Downloads/file.csv'))
os.path.expanderuser()
will automatically expand it to /home/[USERNAME]/
for you.
1
Thank you! I knew I was very close having tried multiple os.path options, but this I hadn't yet. Works like a charm.
– Vitz
Nov 8 at 10:55
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You could rewrite the path using the ~
which replaces /home/[USERNAME]/
, so it would become ~/Downloads/file.csv
. Then, you could use Python's os.path.expanduser()
function as follows:
assert os.path.isfile(os.path.expanduser('~/Downloads/file.csv'))
os.path.expanderuser()
will automatically expand it to /home/[USERNAME]/
for you.
You could rewrite the path using the ~
which replaces /home/[USERNAME]/
, so it would become ~/Downloads/file.csv
. Then, you could use Python's os.path.expanduser()
function as follows:
assert os.path.isfile(os.path.expanduser('~/Downloads/file.csv'))
os.path.expanderuser()
will automatically expand it to /home/[USERNAME]/
for you.
answered Nov 8 at 10:48
rugrln
354
354
1
Thank you! I knew I was very close having tried multiple os.path options, but this I hadn't yet. Works like a charm.
– Vitz
Nov 8 at 10:55
add a comment |
1
Thank you! I knew I was very close having tried multiple os.path options, but this I hadn't yet. Works like a charm.
– Vitz
Nov 8 at 10:55
1
1
Thank you! I knew I was very close having tried multiple os.path options, but this I hadn't yet. Works like a charm.
– Vitz
Nov 8 at 10:55
Thank you! I knew I was very close having tried multiple os.path options, but this I hadn't yet. Works like a charm.
– Vitz
Nov 8 at 10:55
add a comment |
up vote
0
down vote
If you need to get Downloads folder path, than you can use answer to this question: python - Finding the user's "Downloads" folder
add a comment |
up vote
0
down vote
If you need to get Downloads folder path, than you can use answer to this question: python - Finding the user's "Downloads" folder
add a comment |
up vote
0
down vote
up vote
0
down vote
If you need to get Downloads folder path, than you can use answer to this question: python - Finding the user's "Downloads" folder
If you need to get Downloads folder path, than you can use answer to this question: python - Finding the user's "Downloads" folder
answered Nov 8 at 10:49
MihanEntalpo
1,051918
1,051918
add a comment |
add a comment |
Vitz is a new contributor. Be nice, and check out our Code of Conduct.
Vitz is a new contributor. Be nice, and check out our Code of Conduct.
Vitz is a new contributor. Be nice, and check out our Code of Conduct.
Vitz is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206045%2fassert-os-path-isfile-only-working-with-full-path%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Did you try to use "os.path.realpath(file)" to get the real path for your file?
– F.Lira
Nov 8 at 10:51